home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources / tree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-06  |  87.8 KB  |  3,280 lines  |  [TEXT/MPS ]

  1. /* Language-independent node constructors for parse phase of GNU compiler.
  2.    Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file contains the low level primitives for operating on tree nodes,
  22.    including allocation, list operations, interning of identifiers,
  23.    construction of data type nodes and statement nodes,
  24.    and construction of type conversion nodes.  It also contains
  25.    tables index by tree code that describe how to take apart
  26.    nodes of that code.
  27.  
  28.    It is intended to be language-independent, but occasionally
  29.    calls language-dependent routines defined (for C) in typecheck.c.
  30.  
  31.    The low-level allocation routines oballoc and permalloc
  32.    are used also for allocating many other kinds of objects
  33.    by all passes of the compiler.  */
  34.  
  35. #include "config.h"
  36. #include "flags.h"
  37. #include "tree.h"
  38. #include "function.h"
  39. #include "obstack.h"
  40. #include "gvarargs.h"
  41. #include <stdio.h>
  42.  
  43. #define obstack_chunk_alloc xmalloc
  44. #define obstack_chunk_free free
  45.  
  46. int this_type_has_convention;
  47.  
  48. /* Tree nodes of permanent duration are allocated in this obstack.
  49.    They are the identifier nodes, and everything outside of
  50.    the bodies and parameters of function definitions.  */
  51.  
  52. struct obstack permanent_obstack;
  53.  
  54. /* The initial RTL, and all ..._TYPE nodes, in a function
  55.    are allocated in this obstack.  Usually they are freed at the
  56.    end of the function, but if the function is inline they are saved.
  57.    For top-level functions, this is maybepermanent_obstack.
  58.    Separate obstacks are made for nested functions.  */
  59.  
  60. struct obstack *function_maybepermanent_obstack;
  61.  
  62. /* This is the function_maybepermanent_obstack for top-level functions.  */
  63.  
  64. struct obstack maybepermanent_obstack;
  65.  
  66. /* The contents of the current function definition are allocated
  67.    in this obstack, and all are freed at the end of the function.
  68.    For top-level functions, this is temporary_obstack.
  69.    Separate obstacks are made for nested functions.  */
  70.  
  71. struct obstack *function_obstack;
  72.  
  73. /* This is used for reading initializers of global variables.  */
  74.  
  75. struct obstack temporary_obstack;
  76.  
  77. /* The tree nodes of an expression are allocated
  78.    in this obstack, and all are freed at the end of the expression.  */
  79.  
  80. struct obstack momentary_obstack;
  81.  
  82. /* The tree nodes of a declarator are allocated
  83.    in this obstack, and all are freed when the declarator
  84.    has been parsed.  */
  85.  
  86. static struct obstack temp_decl_obstack;
  87.  
  88. /* This points at either permanent_obstack
  89.    or the current function_maybepermanent_obstack.  */
  90.  
  91. struct obstack *saveable_obstack;
  92.  
  93. /* This is same as saveable_obstack during parse and expansion phase;
  94.    it points to the current function's obstack during optimization.
  95.    This is the obstack to be used for creating rtl objects.  */
  96.  
  97. struct obstack *rtl_obstack;
  98.  
  99. /* This points at either permanent_obstack or the current function_obstack.  */
  100.  
  101. struct obstack *current_obstack;
  102.  
  103. /* This points at either permanent_obstack or the current function_obstack
  104.    or momentary_obstack.  */
  105.  
  106. struct obstack *expression_obstack;
  107.  
  108. /* Stack of obstack selections for push_obstacks and pop_obstacks.  */
  109.  
  110. struct obstack_stack
  111. {
  112.   struct obstack_stack *next;
  113.   struct obstack *current;
  114.   struct obstack *saveable;
  115.   struct obstack *expression;
  116.   struct obstack *rtl;
  117. };
  118.  
  119. struct obstack_stack *obstack_stack;
  120.  
  121. /* Obstack for allocating struct obstack_stack entries.  */
  122.  
  123. static struct obstack obstack_stack_obstack;
  124.  
  125. /* Addresses of first objects in some obstacks.
  126.    This is for freeing their entire contents.  */
  127. char *maybepermanent_firstobj;
  128. char *temporary_firstobj;
  129. char *momentary_firstobj;
  130. char *temp_decl_firstobj;
  131.  
  132. /* Nonzero means all ..._TYPE nodes should be allocated permanently.  */
  133.  
  134. int all_types_permanent;
  135.  
  136. /* Stack of places to restore the momentary obstack back to.  */
  137.    
  138. struct momentary_level
  139. {
  140.   /* Pointer back to previous such level.  */
  141.   struct momentary_level *prev;
  142.   /* First object allocated within this level.  */
  143.   char *base;
  144.   /* Value of expression_obstack saved at entry to this level.  */
  145.   struct obstack *obstack;
  146. };
  147.  
  148. struct momentary_level *momentary_stack;
  149.  
  150. /* Table indexed by tree code giving a string containing a character
  151.    classifying the tree code.  Possibilities are
  152.    t, d, s, c, r, <, 1, 2 and e.  See tree.def for details.  */
  153.  
  154. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
  155.  
  156. char *standard_tree_code_type[] = {
  157. #include "tree.def"
  158. };
  159. #undef DEFTREECODE
  160.  
  161. /* Table indexed by tree code giving number of expression
  162.    operands beyond the fixed part of the node structure.
  163.    Not used for types or decls.  */
  164.  
  165. #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
  166.  
  167. int standard_tree_code_length[] = {
  168. #include "tree.def"
  169. };
  170. #undef DEFTREECODE
  171.  
  172. /* Names of tree components.
  173.    Used for printing out the tree and error messages.  */
  174. #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
  175.  
  176. char *standard_tree_code_name[] = {
  177. #include "tree.def"
  178. };
  179. #undef DEFTREECODE
  180.  
  181. /* Table indexed by tree code giving a string containing a character
  182.    classifying the tree code.  Possibilities are
  183.    t, d, s, c, r, e, <, 1 and 2.  See tree.def for details.  */
  184.  
  185. char **tree_code_type;
  186.  
  187. /* Table indexed by tree code giving number of expression
  188.    operands beyond the fixed part of the node structure.
  189.    Not used for types or decls.  */
  190.  
  191. int *tree_code_length;
  192.  
  193. /* Table indexed by tree code giving name of tree code, as a string.  */
  194.  
  195. char **tree_code_name;
  196.  
  197. /* Statistics-gathering stuff.  */
  198. typedef enum
  199. {
  200.   d_kind,
  201.   t_kind,
  202.   b_kind,
  203.   s_kind,
  204.   r_kind,
  205.   e_kind,
  206.   c_kind,
  207.   id_kind,
  208.   op_id_kind,
  209.   perm_list_kind,
  210.   temp_list_kind,
  211.   vec_kind,
  212.   x_kind,
  213.   lang_decl,
  214.   lang_type,
  215.   all_kinds
  216. } tree_node_kind;
  217.  
  218. int tree_node_counts[(int)all_kinds];
  219. int tree_node_sizes[(int)all_kinds];
  220. int id_string_size = 0;
  221.  
  222. char *tree_node_kind_names[] = {
  223.   "decls",
  224.   "types",
  225.   "blocks",
  226.   "stmts",
  227.   "refs",
  228.   "exprs",
  229.   "constants",
  230.   "identifiers",
  231.   "op_identifiers",
  232.   "perm_tree_lists",
  233.   "temp_tree_lists",
  234.   "vecs",
  235.   "random kinds",
  236.   "lang_decl kinds",
  237.   "lang_type kinds"
  238. };
  239.  
  240. /* Hash table for uniquizing IDENTIFIER_NODEs by name.  */
  241.  
  242. #define MAX_HASH_TABLE 1009
  243. static tree hash_table[MAX_HASH_TABLE];    /* id hash buckets */
  244.  
  245. /* 0 while creating built-in identifiers.  */
  246. static int do_identifier_warnings;
  247.  
  248. /* Unique id for next decl created.  */
  249. static int next_decl_uid;
  250.  
  251. extern char *mode_name[];
  252.  
  253. void gcc_obstack_init ();
  254. static tree stabilize_reference_1 ();
  255.  
  256. /* Init the principal obstacks.  */
  257.  
  258. void
  259. init_obstacks ()
  260. {
  261.   gcc_obstack_init (&obstack_stack_obstack);
  262.   gcc_obstack_init (&permanent_obstack);
  263.  
  264.   gcc_obstack_init (&temporary_obstack);
  265.   temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
  266.   gcc_obstack_init (&momentary_obstack);
  267.   momentary_firstobj = (char *) obstack_alloc (&momentary_obstack, 0);
  268.   gcc_obstack_init (&maybepermanent_obstack);
  269.   maybepermanent_firstobj
  270.     = (char *) obstack_alloc (&maybepermanent_obstack, 0);
  271.   gcc_obstack_init (&temp_decl_obstack);
  272.   temp_decl_firstobj = (char *) obstack_alloc (&temp_decl_obstack, 0);
  273.  
  274.   function_obstack = &temporary_obstack;
  275.   function_maybepermanent_obstack = &maybepermanent_obstack;
  276.   current_obstack = &permanent_obstack;
  277.   expression_obstack = &permanent_obstack;
  278.   rtl_obstack = saveable_obstack = &permanent_obstack;
  279.  
  280.   /* Init the hash table of identifiers.  */
  281.   bzero (hash_table, sizeof hash_table);
  282. }
  283.  
  284. void
  285. gcc_obstack_init (obstack)
  286.      struct obstack *obstack;
  287. {
  288.   /* Let particular systems override the size of a chunk.  */
  289. #ifndef OBSTACK_CHUNK_SIZE
  290. #define OBSTACK_CHUNK_SIZE 0
  291. #endif
  292.   /* Let them override the alloc and free routines too.  */
  293. #ifndef OBSTACK_CHUNK_ALLOC
  294. #define OBSTACK_CHUNK_ALLOC xmalloc
  295. #endif
  296. #ifndef OBSTACK_CHUNK_FREE
  297. #define OBSTACK_CHUNK_FREE free
  298. #endif
  299.   _obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
  300.           (void *(*) ()) OBSTACK_CHUNK_ALLOC,
  301.           (void (*) ()) OBSTACK_CHUNK_FREE);
  302. }
  303.  
  304. /* Save all variables describing the current status into the structure *P.
  305.    This is used before starting a nested function.  */
  306.  
  307. void
  308. save_tree_status (p)
  309.      struct function *p;
  310. {
  311.   p->all_types_permanent = all_types_permanent;
  312.   p->momentary_stack = momentary_stack;
  313.   p->maybepermanent_firstobj = maybepermanent_firstobj;
  314.   p->momentary_firstobj = momentary_firstobj;
  315.   p->function_obstack = function_obstack;
  316.   p->function_maybepermanent_obstack = function_maybepermanent_obstack;
  317.   p->current_obstack = current_obstack;
  318.   p->expression_obstack = expression_obstack;
  319.   p->saveable_obstack = saveable_obstack;
  320.   p->rtl_obstack = rtl_obstack;
  321.  
  322.   function_obstack = (struct obstack *) xmalloc (sizeof (struct obstack));
  323.   gcc_obstack_init (function_obstack);
  324.  
  325.   function_maybepermanent_obstack
  326.     = (struct obstack *) xmalloc (sizeof (struct obstack));
  327.   gcc_obstack_init (function_maybepermanent_obstack);
  328.  
  329.   current_obstack = &permanent_obstack;
  330.   expression_obstack = &permanent_obstack;
  331.   rtl_obstack = saveable_obstack = &permanent_obstack;
  332.  
  333.   momentary_firstobj = (char *) obstack_finish (&momentary_obstack);
  334.   maybepermanent_firstobj
  335.     = (char *) obstack_finish (function_maybepermanent_obstack);
  336. }
  337.  
  338. /* Restore all variables describing the current status from the structure *P.
  339.    This is used after a nested function.  */
  340.  
  341. void
  342. restore_tree_status (p)
  343.      struct function *p;
  344. {
  345.   all_types_permanent = p->all_types_permanent;
  346.   momentary_stack = p->momentary_stack;
  347.  
  348.   obstack_free (&momentary_obstack, momentary_firstobj);
  349.   obstack_free (function_obstack, 0);
  350.   obstack_free (function_maybepermanent_obstack, 0);
  351.   free (function_obstack);
  352.  
  353.   momentary_firstobj = p->momentary_firstobj;
  354.   maybepermanent_firstobj = p->maybepermanent_firstobj;
  355.   function_obstack = p->function_obstack;
  356.   function_maybepermanent_obstack = p->function_maybepermanent_obstack;
  357.   current_obstack = p->current_obstack;
  358.   expression_obstack = p->expression_obstack;
  359.   saveable_obstack = p->saveable_obstack;
  360.   rtl_obstack = p->rtl_obstack;
  361. }
  362.  
  363. /* Start allocating on the temporary (per function) obstack.
  364.    This is done in start_function before parsing the function body,
  365.    and before each initialization at top level, and to go back
  366.    to temporary allocation after doing end_temporary_allocation.  */
  367.  
  368. void
  369. temporary_allocation ()
  370. {
  371.   /* Note that function_obstack at top level points to temporary_obstack.
  372.      But within a nested function context, it is a separate obstack.  */
  373.   current_obstack = function_obstack;
  374.   expression_obstack = function_obstack;
  375.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  376.   momentary_stack = 0;
  377. }
  378.  
  379. /* Start allocating on the permanent obstack but don't
  380.    free the temporary data.  After calling this, call
  381.    `permanent_allocation' to fully resume permanent allocation status.  */
  382.  
  383. void
  384. end_temporary_allocation ()
  385. {
  386.   current_obstack = &permanent_obstack;
  387.   expression_obstack = &permanent_obstack;
  388.   rtl_obstack = saveable_obstack = &permanent_obstack;
  389. }
  390.  
  391. /* Resume allocating on the temporary obstack, undoing
  392.    effects of `end_temporary_allocation'.  */
  393.  
  394. void
  395. resume_temporary_allocation ()
  396. {
  397.   current_obstack = function_obstack;
  398.   expression_obstack = function_obstack;
  399.   rtl_obstack = saveable_obstack = function_maybepermanent_obstack;
  400. }
  401.  
  402. /* While doing temporary allocation, switch to allocating in such a
  403.    way as to save all nodes if the function is inlined.  Call
  404.    resume_temporary_allocation to go back to ordinary temporary
  405.    allocation.  */
  406.  
  407. void
  408. saveable_allocation ()
  409. {
  410.   /* Note that function_obstack at top level points to temporary_obstack.
  411.      But within a nested function context, it is a separate obstack.  */
  412.   expression_obstack = current_obstack = saveable_obstack;
  413. }
  414.  
  415. /* Switch to current obstack CURRENT and maybepermanent obstack SAVEABLE,
  416.    recording the previously current obstacks on a stack.
  417.    This does not free any storage in any obstack.  */
  418.  
  419. void
  420. push_obstacks (current, saveable)
  421.      struct obstack *current, *saveable;
  422. {
  423.   struct obstack_stack *p
  424.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  425.                           (sizeof (struct obstack_stack)));
  426.  
  427.   p->current = current_obstack;
  428.   p->saveable = saveable_obstack;
  429.   p->expression = expression_obstack;
  430.   p->rtl = rtl_obstack;
  431.   p->next = obstack_stack;
  432.   obstack_stack = p;
  433.  
  434.   current_obstack = current;
  435.   expression_obstack = current;
  436.   rtl_obstack = saveable_obstack = saveable;
  437. }
  438.  
  439. /* Save the current set of obstacks, but don't change them.  */
  440.  
  441. void
  442. push_obstacks_nochange ()
  443. {
  444.   struct obstack_stack *p
  445.     = (struct obstack_stack *) obstack_alloc (&obstack_stack_obstack,
  446.                           (sizeof (struct obstack_stack)));
  447.  
  448.   p->current = current_obstack;
  449.   p->saveable = saveable_obstack;
  450.   p->expression = expression_obstack;
  451.   p->rtl = rtl_obstack;
  452.   p->next = obstack_stack;
  453.   obstack_stack = p;
  454. }
  455.  
  456. /* Pop the obstack selection stack.  */
  457.  
  458. void
  459. pop_obstacks ()
  460. {
  461.   struct obstack_stack *p = obstack_stack;
  462.   obstack_stack = p->next;
  463.  
  464.   current_obstack = p->current;
  465.   saveable_obstack = p->saveable;
  466.   expression_obstack = p->expression;
  467.   rtl_obstack = p->rtl;
  468.  
  469.   obstack_free (&obstack_stack_obstack, p);
  470. }
  471.  
  472. /* Nonzero if temporary allocation is currently in effect.
  473.    Zero if currently doing permanent allocation.  */
  474.  
  475. int
  476. allocation_temporary_p ()
  477. {
  478.   return current_obstack != &permanent_obstack;
  479. }
  480.  
  481. /* Go back to allocating on the permanent obstack
  482.    and free everything in the temporary obstack.
  483.    This is done in finish_function after fully compiling a function.  */
  484.  
  485. void
  486. permanent_allocation ()
  487. {
  488.   /* Free up previous temporary obstack data */
  489.   obstack_free (&temporary_obstack, temporary_firstobj);
  490.   obstack_free (&momentary_obstack, momentary_firstobj);
  491.   obstack_free (&maybepermanent_obstack, maybepermanent_firstobj);
  492.   obstack_free (&temp_decl_obstack, temp_decl_firstobj);
  493.  
  494.   current_obstack = &permanent_obstack;
  495.   expression_obstack = &permanent_obstack;
  496.   rtl_obstack = saveable_obstack = &permanent_obstack;
  497. }
  498.  
  499. /* Save permanently everything on the maybepermanent_obstack.  */
  500.  
  501. void
  502. preserve_data ()
  503. {
  504.   maybepermanent_firstobj
  505.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  506. }
  507.  
  508. void
  509. preserve_initializer ()
  510. {
  511.   temporary_firstobj
  512.     = (char *) obstack_alloc (&temporary_obstack, 0);
  513.   momentary_firstobj
  514.     = (char *) obstack_alloc (&momentary_obstack, 0);
  515.   maybepermanent_firstobj
  516.     = (char *) obstack_alloc (function_maybepermanent_obstack, 0);
  517. }
  518.  
  519. /* Start allocating new rtl in current_obstack.
  520.    Use resume_temporary_allocation
  521.    to go back to allocating rtl in saveable_obstack.  */
  522.  
  523. void
  524. rtl_in_current_obstack ()
  525. {
  526.   rtl_obstack = current_obstack;
  527. }
  528.  
  529. /* Temporarily allocate rtl from saveable_obstack.  Return 1 if we were
  530.    previously allocating it from current_obstack.  */
  531.  
  532. int
  533. rtl_in_saveable_obstack ()
  534. {
  535.   if (rtl_obstack == current_obstack)
  536.     {
  537.       rtl_obstack = saveable_obstack;
  538.       return 1;
  539.     }
  540.   else
  541.     return 0;
  542. }
  543.  
  544. /* Allocate SIZE bytes in the current obstack
  545.    and return a pointer to them.
  546.    In practice the current obstack is always the temporary one.  */
  547.  
  548. char *
  549. oballoc (size)
  550.      int size;
  551. {
  552.   return (char *) obstack_alloc (current_obstack, size);
  553. }
  554.  
  555. /* Free the object PTR in the current obstack
  556.    as well as everything allocated since PTR.
  557.    In practice the current obstack is always the temporary one.  */
  558.  
  559. void
  560. obfree (ptr)
  561.      char *ptr;
  562. {
  563.   obstack_free (current_obstack, ptr);
  564. }
  565.  
  566. /* Allocate SIZE bytes in the permanent obstack
  567.    and return a pointer to them.  */
  568.  
  569. char *
  570. permalloc (size)
  571.      int size;
  572. {
  573.   return (char *) obstack_alloc (&permanent_obstack, size);
  574. }
  575.  
  576. /* Allocate NELEM items of SIZE bytes in the permanent obstack
  577.    and return a pointer to them.  The storage is cleared before
  578.    returning the value.  */
  579.  
  580. char *
  581. perm_calloc (nelem, size)
  582.      int nelem;
  583.      long size;
  584. {
  585.   char *rval = (char *) obstack_alloc (&permanent_obstack, nelem * size);
  586.   bzero (rval, nelem * size);
  587.   return rval;
  588. }
  589.  
  590. /* Allocate SIZE bytes in the saveable obstack
  591.    and return a pointer to them.  */
  592.  
  593. char *
  594. savealloc (size)
  595.      int size;
  596. {
  597.   return (char *) obstack_alloc (saveable_obstack, size);
  598. }
  599.  
  600. /* Print out which obstack an object is in.  */
  601.  
  602. void
  603. debug_obstack (object)
  604.      char *object;
  605. {
  606.   struct obstack *obstack = NULL;
  607.   char *obstack_name = NULL;
  608.   struct function *p;
  609.  
  610.   for (p = outer_function_chain; p; p = p->next)
  611.     {
  612.       if (_obstack_allocated_p (p->function_obstack, object))
  613.     {
  614.       obstack = p->function_obstack;
  615.       obstack_name = "containing function obstack";
  616.     }
  617.       if (_obstack_allocated_p (p->function_maybepermanent_obstack, object))
  618.     {
  619.       obstack = p->function_maybepermanent_obstack;
  620.       obstack_name = "containing function maybepermanent obstack";
  621.     }
  622.     }
  623.  
  624.   if (_obstack_allocated_p (&obstack_stack_obstack, object))
  625.     {
  626.       obstack = &obstack_stack_obstack;
  627.       obstack_name = "obstack_stack_obstack";
  628.     }
  629.   else if (_obstack_allocated_p (function_obstack, object))
  630.     {
  631.       obstack = function_obstack;
  632.       obstack_name = "function obstack";
  633.     }
  634.   else if (_obstack_allocated_p (&permanent_obstack, object))
  635.     {
  636.       obstack = &permanent_obstack;
  637.       obstack_name = "permanent_obstack";
  638.     }
  639.   else if (_obstack_allocated_p (&momentary_obstack, object))
  640.     {
  641.       obstack = &momentary_obstack;
  642.       obstack_name = "momentary_obstack";
  643.     }
  644.   else if (_obstack_allocated_p (function_maybepermanent_obstack, object))
  645.     {
  646.       obstack = function_maybepermanent_obstack;
  647.       obstack_name = "function maybepermanent obstack";
  648.     }
  649.   else if (_obstack_allocated_p (&temp_decl_obstack, object))
  650.     {
  651.       obstack = &temp_decl_obstack;
  652.       obstack_name = "temp_decl_obstack";
  653.     }
  654.  
  655.   /* Check to see if the object is in the free area of the obstack. */
  656.   if (obstack != NULL)
  657.     {
  658.       if (object >= obstack->next_free
  659.       && object < obstack->chunk_limit)
  660.     fprintf (stderr, "object in free portion of obstack %s.\n",
  661.          obstack_name);
  662.       else
  663.     fprintf (stderr, "object allocated from %s.\n", obstack_name);
  664.     }
  665.   else
  666.     fprintf (stderr, "object not allocated from any obstack.\n");
  667. }
  668.  
  669. /* Return 1 if OBJ is in the permanent obstack.
  670.    This is slow, and should be used only for debugging.
  671.    Use TREE_PERMANENT for other purposes.  */
  672.  
  673. int
  674. object_permanent_p (obj)
  675.      tree obj;
  676. {
  677.   return _obstack_allocated_p (&permanent_obstack, obj);
  678. }
  679.  
  680. /* Start a level of momentary allocation.
  681.    In C, each compound statement has its own level
  682.    and that level is freed at the end of each statement.
  683.    All expression nodes are allocated in the momentary allocation level.  */
  684.  
  685. void
  686. push_momentary ()
  687. {
  688.   struct momentary_level *tem
  689.     = (struct momentary_level *) obstack_alloc (&momentary_obstack,
  690.                         sizeof (struct momentary_level));
  691.   tem->prev = momentary_stack;
  692.   tem->base = (char *) obstack_base (&momentary_obstack);
  693.   tem->obstack = expression_obstack;
  694.   momentary_stack = tem;
  695.   expression_obstack = &momentary_obstack;
  696. }
  697.  
  698. /* Free all the storage in the current momentary-allocation level.
  699.    In C, this happens at the end of each statement.  */
  700.  
  701. void
  702. clear_momentary ()
  703. {
  704.   obstack_free (&momentary_obstack, momentary_stack->base);
  705. }
  706.  
  707. /* Discard a level of momentary allocation.
  708.    In C, this happens at the end of each compound statement.
  709.    Restore the status of expression node allocation
  710.    that was in effect before this level was created.  */
  711.  
  712. void
  713. pop_momentary ()
  714. {
  715.   struct momentary_level *tem = momentary_stack;
  716.   momentary_stack = tem->prev;
  717.   expression_obstack = tem->obstack;
  718.   obstack_free (&momentary_obstack, tem);
  719. }
  720.  
  721. /* Call when starting to parse a declaration:
  722.    make expressions in the declaration last the length of the function.
  723.    Returns an argument that should be passed to resume_momentary later.  */
  724.  
  725. int
  726. suspend_momentary ()
  727. {
  728.   register int tem = expression_obstack == &momentary_obstack;
  729.   expression_obstack = saveable_obstack;
  730.   return tem;
  731. }
  732.  
  733. /* Call when finished parsing a declaration:
  734.    restore the treatment of node-allocation that was
  735.    in effect before the suspension.
  736.    YES should be the value previously returned by suspend_momentary.  */
  737.  
  738. void
  739. resume_momentary (yes)
  740.      int yes;
  741. {
  742.   if (yes)
  743.     expression_obstack = &momentary_obstack;
  744. }
  745.  
  746. /* Init the tables indexed by tree code.
  747.    Note that languages can add to these tables to define their own codes.  */
  748.  
  749. void
  750. init_tree_codes ()
  751. {
  752.   tree_code_type = (char **) xmalloc (sizeof (standard_tree_code_type));
  753.   tree_code_length = (int *) xmalloc (sizeof (standard_tree_code_length));
  754.   tree_code_name = (char **) xmalloc (sizeof (standard_tree_code_name));
  755.   bcopy (standard_tree_code_type, tree_code_type,
  756.      sizeof (standard_tree_code_type));
  757.   bcopy (standard_tree_code_length, tree_code_length,
  758.      sizeof (standard_tree_code_length));
  759.   bcopy (standard_tree_code_name, tree_code_name,
  760.      sizeof (standard_tree_code_name));
  761. }
  762.  
  763. /* Return a newly allocated node of code CODE.
  764.    Initialize the node's unique id and its TREE_PERMANENT flag.
  765.    For decl and type nodes, some other fields are initialized.
  766.    The rest of the node is initialized to zero.
  767.  
  768.    Achoo!  I got a code in the node.  */
  769.  
  770. tree
  771. make_node (code)
  772.      enum tree_code code;
  773. {
  774.   register tree t;
  775.   register int type = TREE_CODE_CLASS (code);
  776.   register int length;
  777.   register struct obstack *obstack = current_obstack;
  778.   register int i;
  779.   register tree_node_kind kind;
  780.  
  781.   switch (type)
  782.     {
  783.     case 'd':  /* A decl node */
  784. #ifdef GATHER_STATISTICS
  785.       kind = d_kind;
  786. #endif
  787.       length = sizeof (struct tree_decl);
  788.       /* All decls in an inline function need to be saved.  */
  789.       if (obstack != &permanent_obstack)
  790.     obstack = saveable_obstack;
  791.       /* PARM_DECLs always go on saveable_obstack, not permanent,
  792.      even though we may make them before the function turns
  793.      on temporary allocation.  */
  794.       else if (code == PARM_DECL)
  795.     obstack = function_maybepermanent_obstack;
  796.       break;
  797.  
  798.     case 't':  /* a type node */
  799. #ifdef GATHER_STATISTICS
  800.       kind = t_kind;
  801. #endif
  802.       length = sizeof (struct tree_type);
  803.       /* All data types are put where we can preserve them if nec.  */
  804.       if (obstack != &permanent_obstack)
  805.     obstack = all_types_permanent ? &permanent_obstack : saveable_obstack;
  806.       break;
  807.  
  808.     case 'b':  /* a lexical block */
  809. #ifdef GATHER_STATISTICS
  810.       kind = b_kind;
  811. #endif
  812.       length = sizeof (struct tree_block);
  813.       /* All BLOCK nodes are put where we can preserve them if nec.  */
  814.       if (obstack != &permanent_obstack)
  815.     obstack = saveable_obstack;
  816.       break;
  817.  
  818.     case 's':  /* an expression with side effects */
  819. #ifdef GATHER_STATISTICS
  820.       kind = s_kind;
  821.       goto usual_kind;
  822. #endif
  823.     case 'r':  /* a reference */
  824. #ifdef GATHER_STATISTICS
  825.       kind = r_kind;
  826.       goto usual_kind;
  827. #endif
  828.     case 'e':  /* an expression */
  829.     case '<':  /* a comparison expression */
  830.     case '1':  /* a unary arithmetic expression */
  831.     case '2':  /* a binary arithmetic expression */
  832. #ifdef GATHER_STATISTICS
  833.       kind = e_kind;
  834.     usual_kind:
  835. #endif
  836.       obstack = expression_obstack;
  837.       /* All BIND_EXPR nodes are put where we can preserve them if nec.  */
  838.       if (code == BIND_EXPR && obstack != &permanent_obstack)
  839.     obstack = saveable_obstack;
  840.       length = sizeof (struct tree_exp)
  841.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  842.       break;
  843.  
  844.     case 'c':  /* a constant */
  845. #ifdef GATHER_STATISTICS
  846.       kind = c_kind;
  847. #endif
  848.       obstack = expression_obstack;
  849.       /* We can't use tree_code_length for this, since the number of words
  850.      is machine-dependent due to varying alignment of `double'.  */
  851.       if (code == REAL_CST)
  852.     {
  853.       length = sizeof (struct tree_real_cst);
  854.       break;
  855.     }
  856.  
  857.     case 'x':  /* something random, like an identifier.  */
  858. #ifdef GATHER_STATISTICS
  859.       if (code == IDENTIFIER_NODE)
  860.     kind = id_kind;
  861.       else if (code == OP_IDENTIFIER)
  862.     kind = op_id_kind;
  863.       else if (code == TREE_VEC)
  864.     kind = vec_kind;
  865.       else
  866.     kind = x_kind;
  867. #endif
  868.       length = sizeof (struct tree_common)
  869.     + tree_code_length[(int) code] * sizeof (char *);
  870.       /* Identifier nodes are always permanent since they are
  871.      unique in a compiler run.  */
  872.       if (code == IDENTIFIER_NODE) obstack = &permanent_obstack;
  873.     }
  874.  
  875.   t = (tree) obstack_alloc (obstack, length);
  876.  
  877. #ifdef GATHER_STATISTICS
  878.   tree_node_counts[(int)kind]++;
  879.   tree_node_sizes[(int)kind] += length;
  880. #endif
  881.  
  882. #ifdef MPW_C
  883.   /* MPW C does better with clearing a byte at a time. */
  884.   for (i = 0; i < length; i++) ((char *) t)[i] = 0;
  885. #else
  886.   /* Clear a word at a time.  */
  887.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  888.     ((int *) t)[i] = 0;
  889.   /* Clear any extra bytes.  */
  890.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  891.     ((char *) t)[i] = 0;
  892. #endif /* MPW_C */
  893.  
  894.   TREE_SET_CODE (t, code);
  895.   if (obstack == &permanent_obstack)
  896.     TREE_PERMANENT (t) = 1;
  897.  
  898.   switch (type)
  899.     {
  900.     case 's':
  901.       TREE_SIDE_EFFECTS (t) = 1;
  902.       TREE_TYPE (t) = void_type_node;
  903.       break;
  904.  
  905.     case 'd':
  906.       if (code != FUNCTION_DECL)
  907.     DECL_ALIGN (t) = 1;
  908.       DECL_IN_SYSTEM_HEADER (t)
  909.     = in_system_header && (obstack == &permanent_obstack);
  910.       DECL_SOURCE_LINE (t) = lineno;
  911.       DECL_SOURCE_FILE (t) = (input_filename) ? input_filename : "<built-in>";
  912.       DECL_UID (t) = next_decl_uid++;
  913.       break;
  914.  
  915.     case 't':
  916.       {
  917.     static unsigned next_type_uid = 1;
  918.  
  919.     TYPE_UID (t) = next_type_uid++;
  920.       }
  921.       TYPE_ALIGN (t) = 1;
  922.       TYPE_MAIN_VARIANT (t) = t;
  923.       break;
  924.  
  925.     case 'c':
  926.       TREE_CONSTANT (t) = 1;
  927.       break;
  928.     }
  929.  
  930.   return t;
  931. }
  932.  
  933. /* Return a new node with the same contents as NODE
  934.    except that its TREE_CHAIN is zero and it has a fresh uid.  */
  935.  
  936. tree
  937. copy_node (node)
  938.      tree node;
  939. {
  940.   register tree t;
  941.   register enum tree_code code = TREE_CODE (node);
  942.   register int length;
  943.   register int i;
  944.  
  945.   switch (TREE_CODE_CLASS (code))
  946.     {
  947.     case 'd':  /* A decl node */
  948.       length = sizeof (struct tree_decl);
  949.       break;
  950.  
  951.     case 't':  /* a type node */
  952.       length = sizeof (struct tree_type);
  953.       break;
  954.  
  955.     case 'b':  /* a lexical block node */
  956.       length = sizeof (struct tree_block);
  957.       break;
  958.  
  959.     case 'r':  /* a reference */
  960.     case 'e':  /* an expression */
  961.     case 's':  /* an expression with side effects */
  962.     case '<':  /* a comparison expression */
  963.     case '1':  /* a unary arithmetic expression */
  964.     case '2':  /* a binary arithmetic expression */
  965.       length = sizeof (struct tree_exp)
  966.     + (tree_code_length[(int) code] - 1) * sizeof (char *);
  967.       break;
  968.  
  969.     case 'c':  /* a constant */
  970.       /* We can't use tree_code_length for this, since the number of words
  971.      is machine-dependent due to varying alignment of `double'.  */
  972.       if (code == REAL_CST)
  973.     {
  974.       length = sizeof (struct tree_real_cst);
  975.       break;
  976.     }
  977.  
  978.     case 'x':  /* something random, like an identifier.  */
  979.       length = sizeof (struct tree_common)
  980.     + tree_code_length[(int) code] * sizeof (char *);
  981.       if (code == TREE_VEC)
  982.     length += (TREE_VEC_LENGTH (node) - 1) * sizeof (char *);
  983.     }
  984.  
  985.   t = (tree) obstack_alloc (current_obstack, length);
  986.  
  987.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  988.     ((int *) t)[i] = ((int *) node)[i];
  989.   /* Clear any extra bytes.  */
  990.   for (i = length / sizeof (int) * sizeof (int); i < length; i++)
  991.     ((char *) t)[i] = ((char *) node)[i];
  992.  
  993.   TREE_CHAIN (t) = 0;
  994.  
  995.   TREE_PERMANENT (t) = (current_obstack == &permanent_obstack);
  996.  
  997.   return t;
  998. }
  999.  
  1000. /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
  1001.    For example, this can copy a list made of TREE_LIST nodes.  */
  1002.  
  1003. tree
  1004. copy_list (list)
  1005.      tree list;
  1006. {
  1007.   tree head;
  1008.   register tree prev, next;
  1009.  
  1010.   if (list == 0)
  1011.     return 0;
  1012.  
  1013.   head = prev = copy_node (list);
  1014.   next = TREE_CHAIN (list);
  1015.   while (next)
  1016.     {
  1017.       TREE_CHAIN (prev) = copy_node (next);
  1018.       prev = TREE_CHAIN (prev);
  1019.       next = TREE_CHAIN (next);
  1020.     }
  1021.   return head;
  1022. }
  1023.  
  1024. #define HASHBITS 30
  1025.  
  1026. /* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
  1027.    If an identifier with that name has previously been referred to,
  1028.    the same node is returned this time.  */
  1029.  
  1030. tree
  1031. get_identifier (text)
  1032.      register char *text;
  1033. {
  1034.   register int hi;
  1035.   register int i;
  1036.   register tree idp;
  1037.   register int len, hash_len;
  1038.  
  1039.   /* Compute length of text in len.  */
  1040.   for (len = 0; text[len]; len++);
  1041.  
  1042.   /* Decide how much of that length to hash on */
  1043.   hash_len = len;
  1044.   if (warn_id_clash && len > id_clash_len)
  1045.     hash_len = id_clash_len;
  1046.  
  1047.   /* Compute hash code */
  1048.   hi = hash_len * 613 + (unsigned)text[0];
  1049.   for (i = 1; i < hash_len; i += 2)
  1050.     hi = ((hi * 613) + (unsigned)(text[i]));
  1051.  
  1052.   hi &= (1 << HASHBITS) - 1;
  1053.   hi %= MAX_HASH_TABLE;
  1054.   
  1055.   /* Search table for identifier */
  1056.   for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1057.     if (IDENTIFIER_LENGTH (idp) == len
  1058.     && IDENTIFIER_POINTER (idp)[0] == text[0]
  1059.     && !bcmp (IDENTIFIER_POINTER (idp), text, len))
  1060.       return idp;        /* <-- return if found */
  1061.  
  1062.   /* Not found; optionally warn about a similar identifier */
  1063.   if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
  1064.     for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
  1065.       if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
  1066.     {
  1067.       warning ("`%s' and `%s' identical in first %d characters",
  1068.            IDENTIFIER_POINTER (idp), text, id_clash_len);
  1069.       break;
  1070.     }
  1071.  
  1072.   if (tree_code_length[(int) IDENTIFIER_NODE] < 0)
  1073.     abort ();            /* set_identifier_size hasn't been called.  */
  1074.  
  1075.   /* Not found, create one, add to chain */
  1076.   idp = make_node (IDENTIFIER_NODE);
  1077.   IDENTIFIER_LENGTH (idp) = len;
  1078. #ifdef GATHER_STATISTICS
  1079.   id_string_size += len;
  1080. #endif
  1081.  
  1082.   IDENTIFIER_POINTER (idp) = obstack_copy0 (&permanent_obstack, text, len);
  1083.  
  1084.   TREE_CHAIN (idp) = hash_table[hi];
  1085.   hash_table[hi] = idp;
  1086.   return idp;            /* <-- return if created */
  1087. }
  1088.  
  1089. /* Enable warnings on similar identifiers (if requested).
  1090.    Done after the built-in identifiers are created.  */
  1091.  
  1092. void
  1093. start_identifier_warnings ()
  1094. {
  1095.   do_identifier_warnings = 1;
  1096. }
  1097.  
  1098. /* Record the size of an identifier node for the language in use.
  1099.    SIZE is the total size in bytes.
  1100.    This is called by the language-specific files.  This must be
  1101.    called before allocating any identifiers.  */
  1102.  
  1103. void
  1104. set_identifier_size (size)
  1105.      int size;
  1106. {
  1107.   tree_code_length[(int) IDENTIFIER_NODE]
  1108.     = (size - sizeof (struct tree_common)) / sizeof (tree);
  1109. }
  1110.  
  1111. /* Return a newly constructed INTEGER_CST node whose constant value
  1112.    is specified by the two ints LOW and HI.
  1113.    The TREE_TYPE is set to `int'. 
  1114.  
  1115.    This function should be used via the `build_int_2' macro.  */
  1116.  
  1117. tree
  1118. build_int_2_wide (low, hi)
  1119.      HOST_WIDE_INT low, hi;
  1120. {
  1121.   register tree t = make_node (INTEGER_CST);
  1122.   TREE_INT_CST_LOW (t) = low;
  1123.   TREE_INT_CST_HIGH (t) = hi;
  1124.   TREE_TYPE (t) = integer_type_node;
  1125.   return t;
  1126. }
  1127.  
  1128. /* Return a new REAL_CST node whose type is TYPE and value is D.  */
  1129.  
  1130. tree
  1131. build_real (type, d)
  1132.      tree type;
  1133.      REAL_VALUE_TYPE d;
  1134. {
  1135.   tree v;
  1136.  
  1137.   /* Check for valid float value for this type on this target machine;
  1138.      if not, can print error message and store a valid value in D.  */
  1139. #ifdef CHECK_FLOAT_VALUE
  1140.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
  1141. #endif
  1142.  
  1143.   v = make_node (REAL_CST);
  1144.   TREE_TYPE (v) = type;
  1145.   TREE_REAL_CST (v) = d;
  1146.   return v;
  1147. }
  1148.  
  1149. /* Return a new REAL_CST node whose type is TYPE
  1150.    and whose value is the integer value of the INTEGER_CST node I.  */
  1151.  
  1152. #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1153.  
  1154. REAL_VALUE_TYPE
  1155. real_value_from_int_cst (i)
  1156.      tree i;
  1157. {
  1158.   REAL_VALUE_TYPE d;
  1159. #ifdef REAL_ARITHMETIC
  1160.   REAL_VALUE_FROM_INT (d, TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i));
  1161. #else /* not REAL_ARITHMETIC */
  1162.   if (TREE_INT_CST_HIGH (i) < 0 && ! TREE_UNSIGNED (TREE_TYPE (i)))
  1163.     {
  1164.       d = (double) (~ TREE_INT_CST_HIGH (i));
  1165.       d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1166.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1167.       d += (double) (unsigned HOST_WIDE_INT) (~ TREE_INT_CST_LOW (i));
  1168.       d = (- d - 1.0);
  1169.     }
  1170.   else
  1171.     {
  1172.       d = (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (i);
  1173.       d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))
  1174.         * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)));
  1175.       d += (double) (unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (i);
  1176.     }
  1177. #endif /* not REAL_ARITHMETIC */
  1178.   return d;
  1179. }
  1180.  
  1181. /* This function can't be implemented if we can't do arithmetic
  1182.    on the float representation.  */
  1183.  
  1184. tree
  1185. build_real_from_int_cst (type, i)
  1186.      tree type;
  1187.      tree i;
  1188. {
  1189.   tree v;
  1190.   REAL_VALUE_TYPE d;
  1191.  
  1192.   v = make_node (REAL_CST);
  1193.   TREE_TYPE (v) = type;
  1194.  
  1195.   d = REAL_VALUE_TRUNCATE (TYPE_MODE (type), real_value_from_int_cst (i));
  1196.   /* Check for valid float value for this type on this target machine;
  1197.      if not, can print error message and store a valid value in D.  */
  1198. #ifdef CHECK_FLOAT_VALUE
  1199.   CHECK_FLOAT_VALUE (TYPE_MODE (type), d);
  1200. #endif
  1201.  
  1202.   TREE_REAL_CST (v) = d;
  1203.   return v;
  1204. }
  1205.  
  1206. #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  1207.  
  1208. /* Return a newly constructed STRING_CST node whose value is
  1209.    the LEN characters at STR.
  1210.    The TREE_TYPE is not initialized.  */
  1211.  
  1212. tree
  1213. build_string (len, str)
  1214.      int len;
  1215.      char *str;
  1216. {
  1217.   register tree s = make_node (STRING_CST);
  1218.   TREE_STRING_LENGTH (s) = len;
  1219.   TREE_STRING_POINTER (s) = obstack_copy0 (saveable_obstack, str, len);
  1220.   return s;
  1221. }
  1222.  
  1223. /* Return a newly constructed COMPLEX_CST node whose value is
  1224.    specified by the real and imaginary parts REAL and IMAG.
  1225.    Both REAL and IMAG should be constant nodes.
  1226.    The TREE_TYPE is not initialized.  */
  1227.  
  1228. tree
  1229. build_complex (real, imag)
  1230.      tree real, imag;
  1231. {
  1232.   register tree t = make_node (COMPLEX_CST);
  1233.   TREE_REALPART (t) = real;
  1234.   TREE_IMAGPART (t) = imag;
  1235.   return t;
  1236. }
  1237.  
  1238. /* Build a newly constructed TREE_VEC node of length LEN.  */
  1239. tree
  1240. make_tree_vec (len)
  1241.      int len;
  1242. {
  1243.   register tree t;
  1244.   register int length = (len-1) * sizeof (tree) + sizeof (struct tree_vec);
  1245.   register struct obstack *obstack = current_obstack;
  1246.   register int i;
  1247.  
  1248. #ifdef GATHER_STATISTICS
  1249.   tree_node_counts[(int)vec_kind]++;
  1250.   tree_node_sizes[(int)vec_kind] += length;
  1251. #endif
  1252.  
  1253.   t = (tree) obstack_alloc (obstack, length);
  1254.  
  1255.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  1256.     ((int *) t)[i] = 0;
  1257.  
  1258.   TREE_SET_CODE (t, TREE_VEC);
  1259.   TREE_VEC_LENGTH (t) = len;
  1260.   if (obstack == &permanent_obstack)
  1261.     TREE_PERMANENT (t) = 1;
  1262.  
  1263.   return t;
  1264. }
  1265.  
  1266. /* Return 1 if EXPR is the integer constant zero.  */
  1267.  
  1268. int
  1269. integer_zerop (expr)
  1270.      tree expr;
  1271. {
  1272.   STRIP_NOPS (expr);
  1273.  
  1274.   return (TREE_CODE (expr) == INTEGER_CST
  1275.       && TREE_INT_CST_LOW (expr) == 0
  1276.       && TREE_INT_CST_HIGH (expr) == 0);
  1277. }
  1278.  
  1279. /* Return 1 if EXPR is the integer constant one.  */
  1280.  
  1281. int
  1282. integer_onep (expr)
  1283.      tree expr;
  1284. {
  1285.   STRIP_NOPS (expr);
  1286.  
  1287.   return (TREE_CODE (expr) == INTEGER_CST
  1288.       && TREE_INT_CST_LOW (expr) == 1
  1289.       && TREE_INT_CST_HIGH (expr) == 0);
  1290. }
  1291.  
  1292. /* Return 1 if EXPR is an integer containing all 1's
  1293.    in as much precision as it contains.  */
  1294.  
  1295. int
  1296. integer_all_onesp (expr)
  1297.      tree expr;
  1298. {
  1299.   register int prec;
  1300.   register int uns;
  1301.  
  1302.   STRIP_NOPS (expr);
  1303.  
  1304.   if (TREE_CODE (expr) != INTEGER_CST)
  1305.     return 0;
  1306.  
  1307.   uns = TREE_UNSIGNED (TREE_TYPE (expr));
  1308.   if (!uns)
  1309.     return TREE_INT_CST_LOW (expr) == -1 && TREE_INT_CST_HIGH (expr) == -1;
  1310.  
  1311.   prec = TYPE_PRECISION (TREE_TYPE (expr));
  1312.   if (prec >= HOST_BITS_PER_WIDE_INT)
  1313.     {
  1314.       int high_value, shift_amount;
  1315.  
  1316.       shift_amount = prec - HOST_BITS_PER_WIDE_INT;
  1317.  
  1318.       if (shift_amount > HOST_BITS_PER_WIDE_INT)
  1319.     /* Can not handle precisions greater than twice the host int size.  */
  1320.     abort ();
  1321.       else if (shift_amount == HOST_BITS_PER_WIDE_INT)
  1322.     /* Shifting by the host word size is undefined according to the ANSI
  1323.        standard, so we must handle this as a special case.  */
  1324.     high_value = -1;
  1325.       else
  1326.     high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
  1327.  
  1328.       return TREE_INT_CST_LOW (expr) == -1
  1329.     && TREE_INT_CST_HIGH (expr) == high_value;
  1330.     }
  1331.   else
  1332.     return TREE_INT_CST_LOW (expr) == ((HOST_WIDE_INT) 1 << prec) - 1;
  1333. }
  1334.  
  1335. /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
  1336.    one bit on).  */
  1337.  
  1338. int
  1339. integer_pow2p (expr)
  1340.      tree expr;
  1341. {
  1342.   HOST_WIDE_INT high, low;
  1343.  
  1344.   STRIP_NOPS (expr);
  1345.  
  1346.   if (TREE_CODE (expr) != INTEGER_CST)
  1347.     return 0;
  1348.  
  1349.   high = TREE_INT_CST_HIGH (expr);
  1350.   low = TREE_INT_CST_LOW (expr);
  1351.  
  1352.   if (high == 0 && low == 0)
  1353.     return 0;
  1354.  
  1355.   return ((high == 0 && (low & (low - 1)) == 0)
  1356.       || (low == 0 && (high & (high - 1)) == 0));
  1357. }
  1358.  
  1359. /* Return 1 if EXPR is the real constant zero.  */
  1360.  
  1361. int
  1362. real_zerop (expr)
  1363.      tree expr;
  1364. {
  1365.   STRIP_NOPS (expr);
  1366.  
  1367.   return (TREE_CODE (expr) == REAL_CST
  1368.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0));
  1369. }
  1370.  
  1371. /* Return 1 if EXPR is the real constant one.  */
  1372.  
  1373. int
  1374. real_onep (expr)
  1375.      tree expr;
  1376. {
  1377.   STRIP_NOPS (expr);
  1378.  
  1379.   return (TREE_CODE (expr) == REAL_CST
  1380.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1));
  1381. }
  1382.  
  1383. /* Return 1 if EXPR is the real constant two.  */
  1384.  
  1385. int
  1386. real_twop (expr)
  1387.      tree expr;
  1388. {
  1389.   STRIP_NOPS (expr);
  1390.  
  1391.   return (TREE_CODE (expr) == REAL_CST
  1392.       && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2));
  1393. }
  1394.  
  1395. /* Nonzero if EXP is a constant or a cast of a constant.  */
  1396.  
  1397. int
  1398. really_constant_p (exp)
  1399.      tree exp;
  1400. {
  1401.   /* This is not quite the same as STRIP_NOPS.  It does more.  */
  1402.   while (TREE_CODE (exp) == NOP_EXPR
  1403.      || TREE_CODE (exp) == CONVERT_EXPR
  1404.      || TREE_CODE (exp) == NON_LVALUE_EXPR)
  1405.     exp = TREE_OPERAND (exp, 0);
  1406.   return TREE_CONSTANT (exp);
  1407. }
  1408.  
  1409. /* Return first list element whose TREE_VALUE is ELEM.
  1410.    Return 0 if ELEM is not it LIST.  */
  1411.  
  1412. tree
  1413. value_member (elem, list)
  1414.      tree elem, list;
  1415. {
  1416.   while (list)
  1417.     {
  1418.       if (elem == TREE_VALUE (list))
  1419.     return list;
  1420.       list = TREE_CHAIN (list);
  1421.     }
  1422.   return NULL_TREE;
  1423. }
  1424.  
  1425. /* Return first list element whose TREE_PURPOSE is ELEM.
  1426.    Return 0 if ELEM is not it LIST.  */
  1427.  
  1428. tree
  1429. purpose_member (elem, list)
  1430.      tree elem, list;
  1431. {
  1432.   while (list)
  1433.     {
  1434.       if (elem == TREE_PURPOSE (list))
  1435.     return list;
  1436.       list = TREE_CHAIN (list);
  1437.     }
  1438.   return NULL_TREE;
  1439. }
  1440.  
  1441. /* Return first list element whose BINFO_TYPE is ELEM.
  1442.    Return 0 if ELEM is not it LIST.  */
  1443.  
  1444. tree
  1445. binfo_member (elem, list)
  1446.      tree elem, list;
  1447. {
  1448.   while (list)
  1449.     {
  1450.       if (elem == BINFO_TYPE (list))
  1451.     return list;
  1452.       list = TREE_CHAIN (list);
  1453.     }
  1454.   return NULL_TREE;
  1455. }
  1456.  
  1457. /* Return nonzero if ELEM is part of the chain CHAIN.  */
  1458.  
  1459. int
  1460. chain_member (elem, chain)
  1461.      tree elem, chain;
  1462. {
  1463.   while (chain)
  1464.     {
  1465.       if (elem == chain)
  1466.     return 1;
  1467.       chain = TREE_CHAIN (chain);
  1468.     }
  1469.  
  1470.   return 0;
  1471. }
  1472.  
  1473. /* Return the length of a chain of nodes chained through TREE_CHAIN.
  1474.    We expect a null pointer to mark the end of the chain.
  1475.    This is the Lisp primitive `length'.  */
  1476.  
  1477. int
  1478. list_length (t)
  1479.      tree t;
  1480. {
  1481.   register tree tail;
  1482.   register int len = 0;
  1483.  
  1484.   for (tail = t; tail; tail = TREE_CHAIN (tail))
  1485.     len++;
  1486.  
  1487.   return len;
  1488. }
  1489.  
  1490. /* Concatenate two chains of nodes (chained through TREE_CHAIN)
  1491.    by modifying the last node in chain 1 to point to chain 2.
  1492.    This is the Lisp primitive `nconc'.  */
  1493.  
  1494. tree
  1495. chainon (op1, op2)
  1496.      tree op1, op2;
  1497. {
  1498.   tree t;
  1499.  
  1500.   if (op1)
  1501.     {
  1502.       for (t = op1; TREE_CHAIN (t); t = TREE_CHAIN (t))
  1503.     if (t == op2) abort ();    /* Circularity being created */
  1504.       if (t == op2) abort ();    /* Circularity being created */
  1505.       TREE_CHAIN (t) = op2;
  1506.       return op1;
  1507.     }
  1508.   else return op2;
  1509. }
  1510.  
  1511. /* Return the last node in a chain of nodes (chained through TREE_CHAIN).  */
  1512.  
  1513. tree
  1514. tree_last (chain)
  1515.      register tree chain;
  1516. {
  1517.   register tree next;
  1518.   if (chain)
  1519.     while (next = TREE_CHAIN (chain))
  1520.       chain = next;
  1521.   return chain;
  1522. }
  1523.  
  1524. /* Reverse the order of elements in the chain T,
  1525.    and return the new head of the chain (old last element).  */
  1526.  
  1527. tree
  1528. nreverse (t)
  1529.      tree t;
  1530. {
  1531.   register tree prev = 0, decl, next;
  1532.   for (decl = t; decl; decl = next)
  1533.     {
  1534.       next = TREE_CHAIN (decl);
  1535.       TREE_CHAIN (decl) = prev;
  1536.       prev = decl;
  1537.     }
  1538.   return prev;
  1539. }
  1540.  
  1541. /* Given a chain CHAIN of tree nodes,
  1542.    construct and return a list of those nodes.  */
  1543.  
  1544. tree
  1545. listify (chain)
  1546.      tree chain;
  1547. {
  1548.   tree result = NULL_TREE;
  1549.   tree in_tail = chain;
  1550.   tree out_tail = NULL_TREE;
  1551.  
  1552.   while (in_tail)
  1553.     {
  1554.       tree next = tree_cons (NULL_TREE, in_tail, NULL_TREE);
  1555.       if (out_tail)
  1556.     TREE_CHAIN (out_tail) = next;
  1557.       else
  1558.     result = next;
  1559.       out_tail = next;
  1560.       in_tail = TREE_CHAIN (in_tail);
  1561.     }
  1562.  
  1563.   return result;
  1564. }
  1565.  
  1566. /* Return a newly created TREE_LIST node whose
  1567.    purpose and value fields are PARM and VALUE.  */
  1568.  
  1569. tree
  1570. build_tree_list (parm, value)
  1571.      tree parm, value;
  1572. {
  1573.   register tree t = make_node (TREE_LIST);
  1574.   TREE_PURPOSE (t) = parm;
  1575.   TREE_VALUE (t) = value;
  1576.   return t;
  1577. }
  1578.  
  1579. /* Similar, but build on the temp_decl_obstack.  */
  1580.  
  1581. tree
  1582. build_decl_list (parm, value)
  1583.      tree parm, value;
  1584. {
  1585.   register tree node;
  1586.   register struct obstack *ambient_obstack = current_obstack;
  1587.   current_obstack = &temp_decl_obstack;
  1588.   node = build_tree_list (parm, value);
  1589.   current_obstack = ambient_obstack;
  1590.   return node;
  1591. }
  1592.  
  1593. /* Return a newly created TREE_LIST node whose
  1594.    purpose and value fields are PARM and VALUE
  1595.    and whose TREE_CHAIN is CHAIN.  */
  1596.  
  1597. tree
  1598. tree_cons (purpose, value, chain)
  1599.      tree purpose, value, chain;
  1600. {
  1601. #if 0
  1602.   register tree node = make_node (TREE_LIST);
  1603. #else
  1604.   register int i;
  1605.   register tree node = (tree) obstack_alloc (current_obstack, sizeof (struct tree_list));
  1606. #ifdef GATHER_STATISTICS
  1607.   tree_node_counts[(int)x_kind]++;
  1608.   tree_node_sizes[(int)x_kind] += sizeof (struct tree_list);
  1609. #endif
  1610.  
  1611.   for (i = (sizeof (struct tree_common) / sizeof (int)) - 1; i >= 0; i--)
  1612.     ((int *) node)[i] = 0;
  1613.  
  1614.   TREE_SET_CODE (node, TREE_LIST);
  1615.   if (current_obstack == &permanent_obstack)
  1616.     TREE_PERMANENT (node) = 1;
  1617. #endif
  1618.  
  1619.   TREE_CHAIN (node) = chain;
  1620.   TREE_PURPOSE (node) = purpose;
  1621.   TREE_VALUE (node) = value;
  1622.   return node;
  1623. }
  1624.  
  1625. /* Similar, but build on the temp_decl_obstack.  */
  1626.  
  1627. tree
  1628. decl_tree_cons (purpose, value, chain)
  1629.      tree purpose, value, chain;
  1630. {
  1631.   register tree node;
  1632.   register struct obstack *ambient_obstack = current_obstack;
  1633.   current_obstack = &temp_decl_obstack;
  1634.   node = tree_cons (purpose, value, chain);
  1635.   current_obstack = ambient_obstack;
  1636.   return node;
  1637. }
  1638.  
  1639. /* Same as `tree_cons' but make a permanent object.  */
  1640.  
  1641. tree
  1642. perm_tree_cons (purpose, value, chain)
  1643.      tree purpose, value, chain;
  1644. {
  1645.   register tree node;
  1646.   register struct obstack *ambient_obstack = current_obstack;
  1647.   current_obstack = &permanent_obstack;
  1648.  
  1649.   node = tree_cons (purpose, value, chain);
  1650.   current_obstack = ambient_obstack;
  1651.   return node;
  1652. }
  1653.  
  1654. /* Same as `tree_cons', but make this node temporary, regardless.  */
  1655.  
  1656. tree
  1657. temp_tree_cons (purpose, value, chain)
  1658.      tree purpose, value, chain;
  1659. {
  1660.   register tree node;
  1661.   register struct obstack *ambient_obstack = current_obstack;
  1662.   current_obstack = &temporary_obstack;
  1663.  
  1664.   node = tree_cons (purpose, value, chain);
  1665.   current_obstack = ambient_obstack;
  1666.   return node;
  1667. }
  1668.  
  1669. /* Same as `tree_cons', but save this node if the function's RTL is saved.  */
  1670.  
  1671. tree
  1672. saveable_tree_cons (purpose, value, chain)
  1673.      tree purpose, value, chain;
  1674. {
  1675.   register tree node;
  1676.   register struct obstack *ambient_obstack = current_obstack;
  1677.   current_obstack = saveable_obstack;
  1678.  
  1679.   node = tree_cons (purpose, value, chain);
  1680.   current_obstack = ambient_obstack;
  1681.   return node;
  1682. }
  1683.  
  1684. /* Return the size nominally occupied by an object of type TYPE
  1685.    when it resides in memory.  The value is measured in units of bytes,
  1686.    and its data type is that normally used for type sizes
  1687.    (which is the first type created by make_signed_type or
  1688.    make_unsigned_type).  */
  1689.  
  1690. tree
  1691. size_in_bytes (type)
  1692.      tree type;
  1693. {
  1694.   if (type == error_mark_node)
  1695.     return integer_zero_node;
  1696.   type = TYPE_MAIN_VARIANT (type);
  1697.   if (TYPE_SIZE (type) == 0)
  1698.     {
  1699.       incomplete_type_error (NULL_TREE, type);
  1700.       return integer_zero_node;
  1701.     }
  1702.   return size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type),
  1703.              size_int (BITS_PER_UNIT));
  1704. }
  1705.  
  1706. /* Return the size of TYPE (in bytes) as an integer,
  1707.    or return -1 if the size can vary.  */
  1708.  
  1709. int
  1710. int_size_in_bytes (type)
  1711.      tree type;
  1712. {
  1713.   int size;
  1714.   if (type == error_mark_node)
  1715.     return 0;
  1716.   type = TYPE_MAIN_VARIANT (type);
  1717.   if (TYPE_SIZE (type) == 0)
  1718.     return -1;
  1719.   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  1720.     return -1;
  1721.   size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  1722.   return (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  1723. }
  1724.  
  1725. /* Return, as an INTEGER_CST node, the number of elements for
  1726.    TYPE (which is an ARRAY_TYPE) minus one. 
  1727.    This counts only elements of the top array.  */
  1728.  
  1729. tree
  1730. array_type_nelts (type)
  1731.      tree type;
  1732. {
  1733.   tree index_type = TYPE_DOMAIN (type);
  1734.   return (tree_int_cst_equal (TYPE_MIN_VALUE (index_type), integer_zero_node)
  1735.       ? TYPE_MAX_VALUE (index_type)
  1736.       : fold (build (MINUS_EXPR, integer_type_node,
  1737.              TYPE_MAX_VALUE (index_type),
  1738.              TYPE_MIN_VALUE (index_type))));
  1739. }
  1740.  
  1741. /* Return nonzero if arg is static -- a reference to an object in
  1742.    static storage.  This is not the same as the C meaning of `static'.  */
  1743.  
  1744. int
  1745. staticp (arg)
  1746.      tree arg;
  1747. {
  1748.   switch (TREE_CODE (arg))
  1749.     {
  1750.     case VAR_DECL:
  1751.     case FUNCTION_DECL:
  1752.     case CONSTRUCTOR:
  1753.       return TREE_STATIC (arg) || DECL_EXTERNAL (arg);
  1754.  
  1755.     case STRING_CST:
  1756.       return 1;
  1757.  
  1758.     case COMPONENT_REF:
  1759.     case BIT_FIELD_REF:
  1760.       return staticp (TREE_OPERAND (arg, 0));
  1761.  
  1762.     case INDIRECT_REF:
  1763.       return TREE_CONSTANT (TREE_OPERAND (arg, 0));
  1764.  
  1765.     case ARRAY_REF:
  1766.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
  1767.       && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
  1768.     return staticp (TREE_OPERAND (arg, 0));
  1769.     }
  1770.  
  1771.   return 0;
  1772. }
  1773.  
  1774. /* This should be applied to any node which may be used in more than one place,
  1775.    but must be evaluated only once.  Normally, the code generator would
  1776.    reevaluate the node each time; this forces it to compute it once and save
  1777.    the result.  This is done by encapsulating the node in a SAVE_EXPR.  */
  1778.  
  1779. tree
  1780. save_expr (expr)
  1781.      tree expr;
  1782. {
  1783.   register tree t = fold (expr);
  1784.  
  1785.   /* We don't care about whether this can be used as an lvalue in this
  1786.      context.  */
  1787.   while (TREE_CODE (t) == NON_LVALUE_EXPR)
  1788.     t = TREE_OPERAND (t, 0);
  1789.  
  1790.   /* If the tree evaluates to a constant, then we don't want to hide that
  1791.      fact (i.e. this allows further folding, and direct checks for constants).
  1792.      However, a read-only object that has side effects cannot be bypassed.
  1793.      Since it is no problem to reevaluate literals, we just return the 
  1794.      literal node. */
  1795.  
  1796.   if (TREE_CONSTANT (t) || (TREE_READONLY (t) && ! TREE_SIDE_EFFECTS (t))
  1797.       || TREE_CODE (t) == SAVE_EXPR)
  1798.     return t;
  1799.  
  1800.   t = build (SAVE_EXPR, TREE_TYPE (expr), t, current_function_decl, NULL_TREE);
  1801.  
  1802.   /* This expression might be placed ahead of a jump to ensure that the
  1803.      value was computed on both sides of the jump.  So make sure it isn't
  1804.      eliminated as dead.  */
  1805.   TREE_SIDE_EFFECTS (t) = 1;
  1806.   return t;
  1807. }
  1808. #ifdef MPW
  1809. #pragma segment TREE1
  1810. #endif
  1811.  
  1812. /* Stabilize a reference so that we can use it any number of times
  1813.    without causing its operands to be evaluated more than once.
  1814.    Returns the stabilized reference.
  1815.  
  1816.    Also allows conversion expressions whose operands are references.
  1817.    Any other kind of expression is returned unchanged.  */
  1818.  
  1819. tree
  1820. stabilize_reference (ref)
  1821.      tree ref;
  1822. {
  1823.   register tree result;
  1824.   register enum tree_code code = TREE_CODE (ref);
  1825.  
  1826.   switch (code)
  1827.     {
  1828.     case VAR_DECL:
  1829.     case PARM_DECL:
  1830.     case RESULT_DECL:
  1831.       /* No action is needed in this case.  */
  1832.       return ref;
  1833.  
  1834.     case NOP_EXPR:
  1835.     case CONVERT_EXPR:
  1836.     case FLOAT_EXPR:
  1837.     case FIX_TRUNC_EXPR:
  1838.     case FIX_FLOOR_EXPR:
  1839.     case FIX_ROUND_EXPR:
  1840.     case FIX_CEIL_EXPR:
  1841.       result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
  1842.       break;
  1843.  
  1844.     case INDIRECT_REF:
  1845.       result = build_nt (INDIRECT_REF,
  1846.              stabilize_reference_1 (TREE_OPERAND (ref, 0)));
  1847.       break;
  1848.  
  1849.     case COMPONENT_REF:
  1850.       result = build_nt (COMPONENT_REF,
  1851.              stabilize_reference (TREE_OPERAND (ref, 0)),
  1852.              TREE_OPERAND (ref, 1));
  1853.       break;
  1854.  
  1855.     case BIT_FIELD_REF:
  1856.       result = build_nt (BIT_FIELD_REF,
  1857.              stabilize_reference (TREE_OPERAND (ref, 0)),
  1858.              stabilize_reference_1 (TREE_OPERAND (ref, 1)),
  1859.              stabilize_reference_1 (TREE_OPERAND (ref, 2)));
  1860.       break;
  1861.  
  1862.     case ARRAY_REF:
  1863.       result = build_nt (ARRAY_REF,
  1864.              stabilize_reference (TREE_OPERAND (ref, 0)),
  1865.              stabilize_reference_1 (TREE_OPERAND (ref, 1)));
  1866.       break;
  1867.  
  1868.       /* If arg isn't a kind of lvalue we recognize, make no change.
  1869.      Caller should recognize the error for an invalid lvalue.  */
  1870.     default:
  1871.       return ref;
  1872.  
  1873.     case ERROR_MARK:
  1874.       return error_mark_node;
  1875.     }
  1876.  
  1877.   TREE_TYPE (result) = TREE_TYPE (ref);
  1878.   TREE_READONLY (result) = TREE_READONLY (ref);
  1879.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
  1880.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
  1881.   TREE_RAISES (result) = TREE_RAISES (ref);
  1882.  
  1883.   return result;
  1884. }
  1885.  
  1886. /* Subroutine of stabilize_reference; this is called for subtrees of
  1887.    references.  Any expression with side-effects must be put in a SAVE_EXPR
  1888.    to ensure that it is only evaluated once.
  1889.  
  1890.    We don't put SAVE_EXPR nodes around everything, because assigning very
  1891.    simple expressions to temporaries causes us to miss good opportunities
  1892.    for optimizations.  Among other things, the opportunity to fold in the
  1893.    addition of a constant into an addressing mode often gets lost, e.g.
  1894.    "y[i+1] += x;".  In general, we take the approach that we should not make
  1895.    an assignment unless we are forced into it - i.e., that any non-side effect
  1896.    operator should be allowed, and that cse should take care of coalescing
  1897.    multiple utterances of the same expression should that prove fruitful.  */
  1898.  
  1899. static tree
  1900. stabilize_reference_1 (e)
  1901.      tree e;
  1902. {
  1903.   register tree result;
  1904.   register int length;
  1905.   register enum tree_code code = TREE_CODE (e);
  1906.  
  1907.   /* We cannot ignore const expressions because it might be a reference
  1908.      to a const array but whose index contains side-effects.  But we can
  1909.      ignore things that are actual constant or that already have been
  1910.      handled by this function.  */
  1911.  
  1912.   if (TREE_CONSTANT (e) || code == SAVE_EXPR)
  1913.     return e;
  1914.  
  1915.   switch (TREE_CODE_CLASS (code))
  1916.     {
  1917.     case 'x':
  1918.     case 't':
  1919.     case 'd':
  1920.     case 'b':
  1921.     case '<':
  1922.     case 's':
  1923.     case 'e':
  1924.     case 'r':
  1925.       /* If the expression has side-effects, then encase it in a SAVE_EXPR
  1926.      so that it will only be evaluated once.  */
  1927.       /* The reference (r) and comparison (<) classes could be handled as
  1928.      below, but it is generally faster to only evaluate them once.  */
  1929.       if (TREE_SIDE_EFFECTS (e))
  1930.     return save_expr (e);
  1931.       return e;
  1932.  
  1933.     case 'c':
  1934.       /* Constants need no processing.  In fact, we should never reach
  1935.      here.  */
  1936.       return e;
  1937.       
  1938.     case '2':
  1939.       /* Recursively stabilize each operand.  */
  1940.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
  1941.              stabilize_reference_1 (TREE_OPERAND (e, 1)));
  1942.       break;
  1943.  
  1944.     case '1':
  1945.       /* Recursively stabilize each operand.  */
  1946.       result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
  1947.       break;
  1948.     }
  1949.   
  1950.   TREE_TYPE (result) = TREE_TYPE (e);
  1951.   TREE_READONLY (result) = TREE_READONLY (e);
  1952.   TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
  1953.   TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
  1954.   TREE_RAISES (result) = TREE_RAISES (e);
  1955.  
  1956.   return result;
  1957. }
  1958.  
  1959. /* Low-level constructors for expressions.  */
  1960.  
  1961. /* Build an expression of code CODE, data type TYPE,
  1962.    and operands as specified by the arguments ARG1 and following arguments.
  1963.    Expressions and reference nodes can be created this way.
  1964.    Constants, decls, types and misc nodes cannot be.  */
  1965.  
  1966. tree
  1967. build (va_alist)
  1968.      va_dcl
  1969. {
  1970.   va_list p;
  1971.   enum tree_code code;
  1972.   register tree t;
  1973.   register int length;
  1974.   register int i;
  1975.  
  1976.   va_start (p);
  1977.  
  1978.   code = va_arg (p, enum tree_code);
  1979.   t = make_node (code);
  1980.   length = tree_code_length[(int) code];
  1981.   TREE_TYPE (t) = va_arg (p, tree);
  1982.  
  1983.   if (length == 2)
  1984.     {
  1985.       /* This is equivalent to the loop below, but faster.  */
  1986.       register tree arg0 = va_arg (p, tree);
  1987.       register tree arg1 = va_arg (p, tree);
  1988.       TREE_OPERAND (t, 0) = arg0;
  1989.       TREE_OPERAND (t, 1) = arg1;
  1990.       if ((arg0 && TREE_SIDE_EFFECTS (arg0))
  1991.       || (arg1 && TREE_SIDE_EFFECTS (arg1)))
  1992.     TREE_SIDE_EFFECTS (t) = 1;
  1993.       TREE_RAISES (t)
  1994.     = (arg0 && TREE_RAISES (arg0)) || (arg1 && TREE_RAISES (arg1));
  1995.     }
  1996.   else if (length == 1)
  1997.     {
  1998.       register tree arg0 = va_arg (p, tree);
  1999.  
  2000.       /* Call build1 for this!  */
  2001.       if (TREE_CODE_CLASS (code) != 's')
  2002.     abort ();
  2003.       TREE_OPERAND (t, 0) = arg0;
  2004.       if (arg0 && TREE_SIDE_EFFECTS (arg0))
  2005.     TREE_SIDE_EFFECTS (t) = 1;
  2006.       TREE_RAISES (t) = (arg0 && TREE_RAISES (arg0));
  2007.     }
  2008.   else
  2009.     {
  2010.       for (i = 0; i < length; i++)
  2011.     {
  2012.       register tree operand = va_arg (p, tree);
  2013.       TREE_OPERAND (t, i) = operand;
  2014.       if (operand)
  2015.         {
  2016.           if (TREE_SIDE_EFFECTS (operand))
  2017.         TREE_SIDE_EFFECTS (t) = 1;
  2018.           if (TREE_RAISES (operand))
  2019.         TREE_RAISES (t) = 1;
  2020.         }
  2021.     }
  2022.     }
  2023.   va_end (p);
  2024.   return t;
  2025. }
  2026.  
  2027. /* Same as above, but only builds for unary operators.
  2028.    Saves lions share of calls to `build'; cuts down use
  2029.    of varargs, which is expensive for RISC machines.  */
  2030. tree
  2031. build1 (code, type, node)
  2032.      enum tree_code code;
  2033.      tree type;
  2034.      tree node;
  2035. {
  2036.   register struct obstack *obstack = current_obstack;
  2037.   register int i, length;
  2038.   register tree_node_kind kind;
  2039.   register tree t;
  2040.  
  2041. #ifdef GATHER_STATISTICS
  2042.   if (TREE_CODE_CLASS (code) == 'r')
  2043.     kind = r_kind;
  2044.   else
  2045.     kind = e_kind;
  2046. #endif
  2047.  
  2048.   obstack = expression_obstack;
  2049.   length = sizeof (struct tree_exp);
  2050.  
  2051.   t = (tree) obstack_alloc (obstack, length);
  2052.  
  2053. #ifdef GATHER_STATISTICS
  2054.   tree_node_counts[(int)kind]++;
  2055.   tree_node_sizes[(int)kind] += length;
  2056. #endif
  2057.  
  2058.   for (i = (length / sizeof (int)) - 1; i >= 0; i--)
  2059.     ((int *) t)[i] = 0;
  2060.  
  2061.   TREE_TYPE (t) = type;
  2062.   TREE_SET_CODE (t, code);
  2063.  
  2064.   if (obstack == &permanent_obstack)
  2065.     TREE_PERMANENT (t) = 1;
  2066.  
  2067.   TREE_OPERAND (t, 0) = node;
  2068.   if (node)
  2069.     {
  2070.       if (TREE_SIDE_EFFECTS (node))
  2071.     TREE_SIDE_EFFECTS (t) = 1;
  2072.       if (TREE_RAISES (node))
  2073.     TREE_RAISES (t) = 1;
  2074.     }
  2075.  
  2076.   return t;
  2077. }
  2078.  
  2079. /* Similar except don't specify the TREE_TYPE
  2080.    and leave the TREE_SIDE_EFFECTS as 0.
  2081.    It is permissible for arguments to be null,
  2082.    or even garbage if their values do not matter.  */
  2083.  
  2084. tree
  2085. build_nt (va_alist)
  2086.      va_dcl
  2087. {
  2088.   va_list p;
  2089.   register enum tree_code code;
  2090.   register tree t;
  2091.   register int length;
  2092.   register int i;
  2093.  
  2094.   va_start (p);
  2095.  
  2096.   code = va_arg (p, enum tree_code);
  2097.   t = make_node (code);
  2098.   length = tree_code_length[(int) code];
  2099.  
  2100.   for (i = 0; i < length; i++)
  2101.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2102.  
  2103.   va_end (p);
  2104.   return t;
  2105. }
  2106.  
  2107. /* Similar to `build_nt', except we build
  2108.    on the temp_decl_obstack, regardless.  */
  2109.  
  2110. tree
  2111. build_parse_node (va_alist)
  2112.      va_dcl
  2113. {
  2114.   register struct obstack *ambient_obstack = expression_obstack;
  2115.   va_list p;
  2116.   register enum tree_code code;
  2117.   register tree t;
  2118.   register int length;
  2119.   register int i;
  2120.  
  2121.   expression_obstack = &temp_decl_obstack;
  2122.  
  2123.   va_start (p);
  2124.  
  2125.   code = va_arg (p, enum tree_code);
  2126.   t = make_node (code);
  2127.   length = tree_code_length[(int) code];
  2128.  
  2129.   for (i = 0; i < length; i++)
  2130.     TREE_OPERAND (t, i) = va_arg (p, tree);
  2131.  
  2132.   va_end (p);
  2133.   expression_obstack = ambient_obstack;
  2134.   return t;
  2135. }
  2136.  
  2137. #if 0
  2138. /* Commented out because this wants to be done very
  2139.    differently.  See cp-lex.c.  */
  2140. tree
  2141. build_op_identifier (op1, op2)
  2142.      tree op1, op2;
  2143. {
  2144.   register tree t = make_node (OP_IDENTIFIER);
  2145.   TREE_PURPOSE (t) = op1;
  2146.   TREE_VALUE (t) = op2;
  2147.   return t;
  2148. }
  2149. #endif
  2150.  
  2151. /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
  2152.    We do NOT enter this node in any sort of symbol table.
  2153.  
  2154.    layout_decl is used to set up the decl's storage layout.
  2155.    Other slots are initialized to 0 or null pointers.  */
  2156.  
  2157. tree
  2158. build_decl (code, name, type)
  2159.      enum tree_code code;
  2160.      tree name, type;
  2161. {
  2162.   register tree t;
  2163.  
  2164.   t = make_node (code);
  2165.  
  2166. /*  if (type == error_mark_node)
  2167.     type = integer_type_node; */
  2168. /* That is not done, deliberately, so that having error_mark_node
  2169.    as the type can suppress useless errors in the use of this variable.  */
  2170.  
  2171.   DECL_NAME (t) = name;
  2172.   DECL_ASSEMBLER_NAME (t) = name;
  2173.   TREE_TYPE (t) = type;
  2174.  
  2175.   if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
  2176.     layout_decl (t, 0);
  2177.   else if (code == FUNCTION_DECL)
  2178.     DECL_MODE (t) = FUNCTION_MODE;
  2179.  
  2180.   return t;
  2181. }
  2182.  
  2183. /* BLOCK nodes are used to represent the structure of binding contours
  2184.    and declarations, once those contours have been exited and their contents
  2185.    compiled.  This information is used for outputting debugging info.  */
  2186.  
  2187. tree
  2188. build_block (vars, tags, subblocks, supercontext, chain)
  2189.      tree vars, tags, subblocks, supercontext, chain;
  2190. {
  2191.   register tree block = make_node (BLOCK);
  2192.   BLOCK_VARS (block) = vars;
  2193.   BLOCK_TYPE_TAGS (block) = tags;
  2194.   BLOCK_SUBBLOCKS (block) = subblocks;
  2195.   BLOCK_SUPERCONTEXT (block) = supercontext;
  2196.   BLOCK_CHAIN (block) = chain;
  2197.   return block;
  2198. }
  2199.  
  2200. /* Return a type like TYPE except that its TYPE_READONLY is CONSTP
  2201.    and its TYPE_VOLATILE is VOLATILEP.
  2202.  
  2203.    Such variant types already made are recorded so that duplicates
  2204.    are not made.
  2205.  
  2206.    A variant types should never be used as the type of an expression.
  2207.    Always copy the variant information into the TREE_READONLY
  2208.    and TREE_THIS_VOLATILE of the expression, and then give the expression
  2209.    as its type the "main variant", the variant whose TYPE_READONLY
  2210.    and TYPE_VOLATILE are zero.  Use TYPE_MAIN_VARIANT to find the
  2211.    main variant.  */
  2212.  
  2213. tree
  2214. build_type_variant (type, constp, volatilep)
  2215.      tree type;
  2216.      int constp, volatilep;
  2217. {
  2218.   register tree t, m = TYPE_MAIN_VARIANT (type);
  2219.   register struct obstack *ambient_obstack = current_obstack;
  2220.  
  2221.   /* Treat any nonzero argument as 1.  */
  2222.   constp = !!constp;
  2223.   volatilep = !!volatilep;
  2224.  
  2225.   /* If not generating auxiliary info, search the chain of variants to see
  2226.      if there is already one there just like the one we need to have.  If so,
  2227.      use that existing one.
  2228.  
  2229.      We don't do this in the case where we are generating aux info because
  2230.      in that case we want each typedef names to get it's own distinct type
  2231.      node, even if the type of this new typedef is the same as some other
  2232.      (existing) type.  */
  2233.  
  2234.   if (!flag_gen_aux_info)
  2235.     for (t = m; t; t = TYPE_NEXT_VARIANT (t))
  2236.       if (constp == TYPE_READONLY (t) && volatilep == TYPE_VOLATILE (t))
  2237.         return t;
  2238.  
  2239.   /* We need a new one.  */
  2240.   current_obstack
  2241.     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
  2242.  
  2243.   t = copy_node (type);
  2244.   TYPE_READONLY (t) = constp;
  2245.   TYPE_VOLATILE (t) = volatilep;
  2246.   TYPE_POINTER_TO (t) = 0;
  2247.   TYPE_REFERENCE_TO (t) = 0;
  2248.  
  2249.   /* Add this type to the chain of variants of TYPE.  */
  2250.   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
  2251.   TYPE_NEXT_VARIANT (m) = t;
  2252.  
  2253.   current_obstack = ambient_obstack;
  2254.   return t;
  2255. }
  2256.  
  2257. /* Create a new variant of TYPE, equivalent but distinct.
  2258.    This is so the caller can modify it.  */
  2259.  
  2260. tree
  2261. build_type_copy (type)
  2262.      tree type;
  2263. {
  2264.   register tree t, m = TYPE_MAIN_VARIANT (type);
  2265.   register struct obstack *ambient_obstack = current_obstack;
  2266.  
  2267.   current_obstack
  2268.     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
  2269.  
  2270.   t = copy_node (type);
  2271.   TYPE_POINTER_TO (t) = 0;
  2272.   TYPE_REFERENCE_TO (t) = 0;
  2273.  
  2274.   /* Add this type to the chain of variants of TYPE.  */
  2275.   TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
  2276.   TYPE_NEXT_VARIANT (m) = t;
  2277.  
  2278.   current_obstack = ambient_obstack;
  2279.   return t;
  2280. }
  2281.  
  2282. /* Hashing of types so that we don't make duplicates.
  2283.    The entry point is `type_hash_canon'.  */
  2284.  
  2285. /* Each hash table slot is a bucket containing a chain
  2286.    of these structures.  */
  2287.  
  2288. struct type_hash
  2289. {
  2290.   struct type_hash *next;    /* Next structure in the bucket.  */
  2291.   int hashcode;            /* Hash code of this type.  */
  2292.   tree type;            /* The type recorded here.  */
  2293. };
  2294.  
  2295. /* Now here is the hash table.  When recording a type, it is added
  2296.    to the slot whose index is the hash code mod the table size.
  2297.    Note that the hash table is used for several kinds of types
  2298.    (function types, array types and array index range types, for now).
  2299.    While all these live in the same table, they are completely independent,
  2300.    and the hash code is computed differently for each of these.  */
  2301.  
  2302. #define TYPE_HASH_SIZE 59
  2303. struct type_hash *type_hash_table[TYPE_HASH_SIZE];
  2304.  
  2305. /* Here is how primitive or already-canonicalized types' hash
  2306.    codes are made.  */
  2307. #define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
  2308.  
  2309. /* Compute a hash code for a list of types (chain of TREE_LIST nodes
  2310.    with types in the TREE_VALUE slots), by adding the hash codes
  2311.    of the individual types.  */
  2312.  
  2313. int
  2314. type_hash_list (list)
  2315.      tree list;
  2316. {
  2317.   register int hashcode;
  2318.   register tree tail;
  2319.   for (hashcode = 0, tail = list; tail; tail = TREE_CHAIN (tail))
  2320.     hashcode += TYPE_HASH (TREE_VALUE (tail));
  2321.   return hashcode;
  2322. }
  2323.  
  2324. /* Look in the type hash table for a type isomorphic to TYPE.
  2325.    If one is found, return it.  Otherwise return 0.  */
  2326.  
  2327. tree
  2328. type_hash_lookup (hashcode, type)
  2329.      int hashcode;
  2330.      tree type;
  2331. {
  2332.   register struct type_hash *h;
  2333.   for (h = type_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next)
  2334.     if (h->hashcode == hashcode
  2335.     && TREE_CODE (h->type) == TREE_CODE (type)
  2336.     && TREE_TYPE (h->type) == TREE_TYPE (type)
  2337.     && (TYPE_MAX_VALUE (h->type) == TYPE_MAX_VALUE (type)
  2338.         || tree_int_cst_equal (TYPE_MAX_VALUE (h->type),
  2339.                    TYPE_MAX_VALUE (type)))
  2340.     && (TYPE_MIN_VALUE (h->type) == TYPE_MIN_VALUE (type)
  2341.         || tree_int_cst_equal (TYPE_MIN_VALUE (h->type),
  2342.                    TYPE_MIN_VALUE (type)))
  2343.     /* Call conventions have to match.  For anything except
  2344.        specially declared functions, these will both be 0. */
  2345. #ifdef COMPARE_CALL_CONVENTION
  2346.     && COMPARE_CALL_CONVENTION(TYPE_CALL_CONVENTION (h->type),
  2347.                    TYPE_CALL_CONVENTION (type))
  2348. #endif
  2349.     && (TYPE_DOMAIN (h->type) == TYPE_DOMAIN (type)
  2350.         || (TYPE_DOMAIN (h->type)
  2351.         && TREE_CODE (TYPE_DOMAIN (h->type)) == TREE_LIST
  2352.         && TYPE_DOMAIN (type)
  2353.         && TREE_CODE (TYPE_DOMAIN (type)) == TREE_LIST
  2354.         && type_list_equal (TYPE_DOMAIN (h->type), TYPE_DOMAIN (type)))))
  2355.       return h->type;
  2356.   return 0;
  2357. }
  2358.  
  2359. /* Add an entry to the type-hash-table
  2360.    for a type TYPE whose hash code is HASHCODE.  */
  2361.  
  2362. void
  2363. type_hash_add (hashcode, type)
  2364.      int hashcode;
  2365.      tree type;
  2366. {
  2367.   register struct type_hash *h;
  2368.  
  2369.   h = (struct type_hash *) oballoc (sizeof (struct type_hash));
  2370.   h->hashcode = hashcode;
  2371.   h->type = type;
  2372.   h->next = type_hash_table[hashcode % TYPE_HASH_SIZE];
  2373.   type_hash_table[hashcode % TYPE_HASH_SIZE] = h;
  2374. }
  2375.  
  2376. /* Given TYPE, and HASHCODE its hash code, return the canonical
  2377.    object for an identical type if one already exists.
  2378.    Otherwise, return TYPE, and record it as the canonical object
  2379.    if it is a permanent object.
  2380.  
  2381.    To use this function, first create a type of the sort you want.
  2382.    Then compute its hash code from the fields of the type that
  2383.    make it different from other similar types.
  2384.    Then call this function and use the value.
  2385.    This function frees the type you pass in if it is a duplicate.  */
  2386.  
  2387. /* Set to 1 to debug without canonicalization.  Never set by program.  */
  2388. int debug_no_type_hash = 0;
  2389.  
  2390. tree
  2391. type_hash_canon (hashcode, type)
  2392.      int hashcode;
  2393.      tree type;
  2394. {
  2395.   tree t1;
  2396.  
  2397.   if (debug_no_type_hash)
  2398.     return type;
  2399.  
  2400.   t1 = type_hash_lookup (hashcode, type);
  2401.   if (t1 != 0)
  2402.     {
  2403.       struct obstack *o
  2404.     = TREE_PERMANENT (type) ? &permanent_obstack : saveable_obstack;
  2405.       obstack_free (o, type);
  2406. #ifdef GATHER_STATISTICS
  2407.       tree_node_counts[(int)t_kind]--;
  2408.       tree_node_sizes[(int)t_kind] -= sizeof (struct tree_type);
  2409. #endif
  2410.       return t1;
  2411.     }
  2412.  
  2413.   /* If this is a new type, record it for later reuse.  */
  2414.   if (current_obstack == &permanent_obstack)
  2415.     type_hash_add (hashcode, type);
  2416.  
  2417.   return type;
  2418. }
  2419.  
  2420. /* Given two lists of types
  2421.    (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
  2422.    return 1 if the lists contain the same types in the same order.
  2423.    Also, the TREE_PURPOSEs must match.  */
  2424.  
  2425. int
  2426. type_list_equal (l1, l2)
  2427.      tree l1, l2;
  2428. {
  2429.   register tree t1, t2;
  2430.   for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  2431.     {
  2432.       if (TREE_VALUE (t1) != TREE_VALUE (t2))
  2433.     return 0;
  2434.       if (TREE_PURPOSE (t1) != TREE_PURPOSE (t2))
  2435.     {
  2436.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  2437.       if (cmp < 0)
  2438.         abort ();
  2439.       if (cmp == 0)
  2440.         return 0;
  2441.     }
  2442.     }
  2443.  
  2444.   return t1 == t2;
  2445. }
  2446.  
  2447. /* Nonzero if integer constants T1 and T2
  2448.    represent the same constant value.  */
  2449.  
  2450. int
  2451. tree_int_cst_equal (t1, t2)
  2452.      tree t1, t2;
  2453. {
  2454.   if (t1 == t2)
  2455.     return 1;
  2456.   if (t1 == 0 || t2 == 0)
  2457.     return 0;
  2458.   if (TREE_CODE (t1) == INTEGER_CST
  2459.       && TREE_CODE (t2) == INTEGER_CST
  2460.       && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  2461.       && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
  2462.     return 1;
  2463.   return 0;
  2464. }
  2465.  
  2466. /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
  2467.    The precise way of comparison depends on their data type.  */
  2468.  
  2469. int
  2470. tree_int_cst_lt (t1, t2)
  2471.      tree t1, t2;
  2472. {
  2473.   if (t1 == t2)
  2474.     return 0;
  2475.  
  2476.   if (!TREE_UNSIGNED (TREE_TYPE (t1)))
  2477.     return INT_CST_LT (t1, t2);
  2478.   return INT_CST_LT_UNSIGNED (t1, t2);
  2479. }
  2480.  
  2481. /* Compare two constructor-element-type constants.  */
  2482. int
  2483. simple_cst_list_equal (l1, l2)
  2484.      tree l1, l2;
  2485. {
  2486.   while (l1 != NULL_TREE && l2 != NULL_TREE)
  2487.     {
  2488.       int cmp = simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2));
  2489.       if (cmp < 0)
  2490.     abort ();
  2491.       if (cmp == 0)
  2492.     return 0;
  2493.       l1 = TREE_CHAIN (l1);
  2494.       l2 = TREE_CHAIN (l2);
  2495.     }
  2496.   return (l1 == l2);
  2497. }
  2498.  
  2499. /* Return truthvalue of whether T1 is the same tree structure as T2.
  2500.    Return 1 if they are the same.
  2501.    Return 0 if they are understandably different.
  2502.    Return -1 if either contains tree structure not understood by
  2503.    this function.  */
  2504.  
  2505. int
  2506. simple_cst_equal (t1, t2)
  2507.      tree t1, t2;
  2508. {
  2509.   register enum tree_code code1, code2;
  2510.   int cmp;
  2511.  
  2512.   if (t1 == t2)
  2513.     return 1;
  2514.   if (t1 == 0 || t2 == 0)
  2515.     return 0;
  2516.  
  2517.   code1 = TREE_CODE (t1);
  2518.   code2 = TREE_CODE (t2);
  2519.  
  2520.   if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
  2521.     if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
  2522.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2523.     else
  2524.       return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
  2525.   else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
  2526.        || code2 == NON_LVALUE_EXPR)
  2527.     return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
  2528.  
  2529.   if (code1 != code2)
  2530.     return 0;
  2531.  
  2532.   switch (code1)
  2533.     {
  2534.     case INTEGER_CST:
  2535.       return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
  2536.     && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2);
  2537.  
  2538.     case REAL_CST:
  2539.       return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
  2540.  
  2541.     case STRING_CST:
  2542.       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
  2543.     && !bcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
  2544.           TREE_STRING_LENGTH (t1));
  2545.  
  2546.     case CONSTRUCTOR:
  2547.       abort ();
  2548.  
  2549.     case SAVE_EXPR:
  2550.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2551.  
  2552.     case CALL_EXPR:
  2553.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2554.       if (cmp <= 0)
  2555.     return cmp;
  2556.       return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  2557.  
  2558.     case TARGET_EXPR:
  2559.       /* Special case: if either target is an unallocated VAR_DECL,
  2560.      it means that it's going to be unified with whatever the
  2561.      TARGET_EXPR is really supposed to initialize, so treat it
  2562.      as being equivalent to anything.  */
  2563.       if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
  2564.        && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
  2565.        && DECL_RTL (TREE_OPERAND (t1, 0)) == 0)
  2566.       || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
  2567.           && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
  2568.           && DECL_RTL (TREE_OPERAND (t2, 0)) == 0))
  2569.     cmp = 1;
  2570.       else
  2571.     cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2572.       if (cmp <= 0)
  2573.     return cmp;
  2574.       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  2575.  
  2576.     case WITH_CLEANUP_EXPR:
  2577.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2578.       if (cmp <= 0)
  2579.     return cmp;
  2580.       return simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t1, 2));
  2581.  
  2582.     case COMPONENT_REF:
  2583.       if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
  2584.     return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2585.       return 0;
  2586.  
  2587.     case BIT_FIELD_REF:
  2588.       return (simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
  2589.           && simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1))
  2590.           && simple_cst_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2)));
  2591.  
  2592.     case VAR_DECL:
  2593.     case PARM_DECL:
  2594.     case CONST_DECL:
  2595.     case FUNCTION_DECL:
  2596.       return 0;
  2597.  
  2598.     case PLUS_EXPR:
  2599.     case MINUS_EXPR:
  2600.     case MULT_EXPR:
  2601.     case TRUNC_DIV_EXPR:
  2602.     case TRUNC_MOD_EXPR:
  2603.     case LSHIFT_EXPR:
  2604.     case RSHIFT_EXPR:
  2605.       cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2606.       if (cmp <= 0)
  2607.     return cmp;
  2608.       return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
  2609.  
  2610.     case NEGATE_EXPR:
  2611.     case ADDR_EXPR:
  2612.     case REFERENCE_EXPR:
  2613.     case INDIRECT_REF:
  2614.       return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
  2615.  
  2616.     default:
  2617. #if 0
  2618.       return lang_simple_cst_equal (t1, t2);
  2619. #else
  2620.       return -1;
  2621. #endif
  2622.     }
  2623. }
  2624.  
  2625. /* Constructors for pointer, array and function types.
  2626.    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
  2627.    constructed by language-dependent code, not here.)  */
  2628.  
  2629. /* Construct, lay out and return the type of pointers to TO_TYPE.
  2630.    If such a type has already been constructed, reuse it.  */
  2631.  
  2632. tree
  2633. build_pointer_type (to_type)
  2634.      tree to_type;
  2635. {
  2636.   register tree t = TYPE_POINTER_TO (to_type);
  2637.   register struct obstack *ambient_obstack = current_obstack;
  2638.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  2639.  
  2640.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  2641.  
  2642.   if (t)
  2643.     return t;
  2644.  
  2645.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  2646.   if (TREE_PERMANENT (to_type))
  2647.     {
  2648.       current_obstack = &permanent_obstack;
  2649.       saveable_obstack = &permanent_obstack;
  2650.     }
  2651.  
  2652.   t = make_node (POINTER_TYPE);
  2653.   TREE_TYPE (t) = to_type;
  2654.  
  2655.   /* Record this type as the pointer to TO_TYPE.  */
  2656.   TYPE_POINTER_TO (to_type) = t;
  2657.  
  2658.   /* Lay out the type.  This function has many callers that are concerned
  2659.      with expression-construction, and this simplifies them all.
  2660.      Also, it guarantees the TYPE_SIZE is permanent if the type is.  */
  2661.   layout_type (t);
  2662.  
  2663.   current_obstack = ambient_obstack;
  2664.   saveable_obstack = ambient_saveable_obstack;
  2665.   return t;
  2666. }
  2667.  
  2668. /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
  2669.    MAXVAL should be the maximum value in the domain
  2670.    (one less than the length of the array).  */
  2671.  
  2672. tree
  2673. build_index_type (maxval)
  2674.      tree maxval;
  2675. {
  2676.   register tree itype = make_node (INTEGER_TYPE);
  2677.   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  2678.   TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
  2679.   TREE_TYPE (TYPE_MIN_VALUE (itype)) = sizetype;
  2680.   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
  2681.   TYPE_MODE (itype) = TYPE_MODE (sizetype);
  2682.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  2683.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  2684.   if (TREE_CODE (maxval) == INTEGER_CST)
  2685.     {
  2686.       int maxint = (int) TREE_INT_CST_LOW (maxval);
  2687.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  2688.     }
  2689.   else
  2690.     return itype;
  2691. }
  2692.  
  2693. /* Just like build_index_type, but takes lowval and highval instead
  2694.    of just highval (maxval). */
  2695.  
  2696. tree
  2697. build_index_2_type (lowval,highval)
  2698.      tree lowval, highval;
  2699. {
  2700.   register tree itype = make_node (INTEGER_TYPE);
  2701.   TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  2702.   TYPE_MIN_VALUE (itype) = convert (sizetype, lowval);
  2703.   TYPE_MAX_VALUE (itype) = convert (sizetype, highval);
  2704.   TYPE_MODE (itype) = TYPE_MODE (sizetype);
  2705.   TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
  2706.   TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
  2707.   if ((TREE_CODE (lowval) == INTEGER_CST)
  2708.       && (TREE_CODE (highval) == INTEGER_CST))
  2709.     {
  2710.       HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval);
  2711.       HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval);
  2712.       int maxint = (int) (highint - lowint);
  2713.       return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
  2714.     }
  2715.   else
  2716.     return itype;
  2717. }
  2718.  
  2719. /* Return nonzero iff ITYPE1 and ITYPE2 are equal (in the LISP sense).
  2720.    Needed because when index types are not hashed, equal index types
  2721.    built at different times appear distinct, even though structurally,
  2722.    they are not.  */
  2723.  
  2724. int
  2725. index_type_equal (itype1, itype2)
  2726.      tree itype1, itype2;
  2727. {
  2728.   if (TREE_CODE (itype1) != TREE_CODE (itype2))
  2729.     return 0;
  2730.   if (TREE_CODE (itype1) == INTEGER_TYPE)
  2731.     {
  2732.       if (TYPE_PRECISION (itype1) != TYPE_PRECISION (itype2)
  2733.       || TYPE_MODE (itype1) != TYPE_MODE (itype2)
  2734.       || ! simple_cst_equal (TYPE_SIZE (itype1), TYPE_SIZE (itype2))
  2735.       || TYPE_ALIGN (itype1) != TYPE_ALIGN (itype2))
  2736.     return 0;
  2737.       if (simple_cst_equal (TYPE_MIN_VALUE (itype1), TYPE_MIN_VALUE (itype2))
  2738.       && simple_cst_equal (TYPE_MAX_VALUE (itype1), TYPE_MAX_VALUE (itype2)))
  2739.     return 1;
  2740.     }
  2741.   return 0;
  2742. }
  2743.  
  2744. /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
  2745.    and number of elements specified by the range of values of INDEX_TYPE.
  2746.    If such a type has already been constructed, reuse it.  */
  2747.  
  2748. tree
  2749. build_array_type (elt_type, index_type)
  2750.      tree elt_type, index_type;
  2751. {
  2752.   register tree t;
  2753.   int hashcode;
  2754.  
  2755.   if (TREE_CODE (elt_type) == FUNCTION_TYPE)
  2756.     {
  2757.       error ("arrays of functions are not meaningful");
  2758.       elt_type = integer_type_node;
  2759.     }
  2760.  
  2761.   /* Make sure TYPE_POINTER_TO (elt_type) is filled in.  */
  2762.   build_pointer_type (elt_type);
  2763.  
  2764.   /* Allocate the array after the pointer type,
  2765.      in case we free it in type_hash_canon.  */
  2766.   t = make_node (ARRAY_TYPE);
  2767.   TREE_TYPE (t) = elt_type;
  2768.   TYPE_DOMAIN (t) = index_type;
  2769.  
  2770.   if (index_type == 0)
  2771.     return t;
  2772.  
  2773.   hashcode = TYPE_HASH (elt_type) + TYPE_HASH (index_type);
  2774.   t = type_hash_canon (hashcode, t);
  2775.  
  2776.   if (TYPE_SIZE (t) == 0)
  2777.     layout_type (t);
  2778.   return t;
  2779. }
  2780.  
  2781. /* Construct, lay out and return
  2782.    the type of functions returning type VALUE_TYPE
  2783.    given arguments of types ARG_TYPES.
  2784.    ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
  2785.    are data type nodes for the arguments of the function.
  2786.    If such a type has already been constructed, reuse it.  */
  2787.  
  2788. tree
  2789. build_function_type (value_type, arg_types)
  2790.      tree value_type, arg_types;
  2791. {
  2792.   register tree t;
  2793.   int hashcode;
  2794.  
  2795.   if (TREE_CODE (value_type) == FUNCTION_TYPE
  2796.       || TREE_CODE (value_type) == ARRAY_TYPE)
  2797.     {
  2798.       error ("function return type cannot be function or array");
  2799.       value_type = integer_type_node;
  2800.     }
  2801.  
  2802.   /* Make a node of the sort we want.  */
  2803.   t = make_node (FUNCTION_TYPE);
  2804.   TREE_TYPE (t) = value_type;
  2805.   TYPE_ARG_TYPES (t) = arg_types;
  2806.  
  2807. #ifdef SPECIAL_CALLING_CONVENTIONS
  2808.   /* If the function type being built has a special calling convention,
  2809.      give it an object to record the info in. */
  2810.   if (this_type_has_convention)
  2811.     {
  2812.       INIT_SPECIAL_CALLING_CONVENTIONS (t);
  2813.       /* Reset the flag so it doesn't contaminate any other
  2814.      function types. */
  2815.       this_type_has_convention = 0;
  2816.     }
  2817. #endif
  2818.  
  2819.   /* If we already have such a type, use the old one and free this one.  */
  2820.   hashcode = TYPE_HASH (value_type) + type_hash_list (arg_types);
  2821.   t = type_hash_canon (hashcode, t);
  2822.  
  2823.   if (TYPE_SIZE (t) == 0)
  2824.     layout_type (t);
  2825.   return t;
  2826. }
  2827.  
  2828. /* Build the node for the type of references-to-TO_TYPE.  */
  2829.  
  2830. tree
  2831. build_reference_type (to_type)
  2832.      tree to_type;
  2833. {
  2834.   register tree t = TYPE_REFERENCE_TO (to_type);
  2835.   register struct obstack *ambient_obstack = current_obstack;
  2836.   register struct obstack *ambient_saveable_obstack = saveable_obstack;
  2837.  
  2838.   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
  2839.  
  2840.   if (t)
  2841.     return t;
  2842.  
  2843.   /* We need a new one.  If TO_TYPE is permanent, make this permanent too.  */
  2844.   if (TREE_PERMANENT (to_type))
  2845.     {
  2846.       current_obstack = &permanent_obstack;
  2847.       saveable_obstack = &permanent_obstack;
  2848.     }
  2849.  
  2850.   t = make_node (REFERENCE_TYPE);
  2851.   TREE_TYPE (t) = to_type;
  2852.  
  2853.   /* Record this type as the pointer to TO_TYPE.  */
  2854.   TYPE_REFERENCE_TO (to_type) = t;
  2855.  
  2856.   layout_type (t);
  2857.  
  2858.   current_obstack = ambient_obstack;
  2859.   saveable_obstack = ambient_saveable_obstack;
  2860.   return t;
  2861. }
  2862.  
  2863. /* Construct, lay out and return the type of methods belonging to class
  2864.    BASETYPE and whose arguments and values are described by TYPE.
  2865.    If that type exists already, reuse it.
  2866.    TYPE must be a FUNCTION_TYPE node.  */
  2867.  
  2868. tree
  2869. build_method_type (basetype, type)
  2870.      tree basetype, type;
  2871. {
  2872.   register tree t;
  2873.   int hashcode;
  2874.  
  2875.   /* Make a node of the sort we want.  */
  2876.   t = make_node (METHOD_TYPE);
  2877.  
  2878.   if (TREE_CODE (type) != FUNCTION_TYPE)
  2879.     abort ();
  2880.  
  2881.   TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  2882.   TREE_TYPE (t) = TREE_TYPE (type);
  2883.  
  2884.   /* The actual arglist for this function includes a "hidden" argument
  2885.      which is "this".  Put it into the list of argument types.  */
  2886.  
  2887.   TYPE_ARG_TYPES (t)
  2888.     = tree_cons (NULL_TREE,
  2889.          build_pointer_type (basetype), TYPE_ARG_TYPES (type));
  2890.  
  2891.   /* If we already have such a type, use the old one and free this one.  */
  2892.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  2893.   t = type_hash_canon (hashcode, t);
  2894.  
  2895.   if (TYPE_SIZE (t) == 0)
  2896.     layout_type (t);
  2897.  
  2898.   return t;
  2899. }
  2900.  
  2901. /* Construct, lay out and return the type of methods belonging to class
  2902.    BASETYPE and whose arguments and values are described by TYPE.
  2903.    If that type exists already, reuse it.
  2904.    TYPE must be a FUNCTION_TYPE node.  */
  2905.  
  2906. tree
  2907. build_offset_type (basetype, type)
  2908.      tree basetype, type;
  2909. {
  2910.   register tree t;
  2911.   int hashcode;
  2912.  
  2913.   /* Make a node of the sort we want.  */
  2914.   t = make_node (OFFSET_TYPE);
  2915.  
  2916.   TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
  2917.   TREE_TYPE (t) = type;
  2918.  
  2919.   /* If we already have such a type, use the old one and free this one.  */
  2920.   hashcode = TYPE_HASH (basetype) + TYPE_HASH (type);
  2921.   t = type_hash_canon (hashcode, t);
  2922.  
  2923.   if (TYPE_SIZE (t) == 0)
  2924.     layout_type (t);
  2925.  
  2926.   return t;
  2927. }
  2928.  
  2929. /* Create a complex type whose components are COMPONENT_TYPE.  */
  2930.  
  2931. tree
  2932. build_complex_type (component_type)
  2933.      tree component_type;
  2934. {
  2935.   register tree t;
  2936.   int hashcode;
  2937.  
  2938.   /* Make a node of the sort we want.  */
  2939.   t = make_node (COMPLEX_TYPE);
  2940.  
  2941.   TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
  2942.   TYPE_VOLATILE (t) = TYPE_VOLATILE (component_type);
  2943.   TYPE_READONLY (t) = TYPE_READONLY (component_type);
  2944.  
  2945.   /* If we already have such a type, use the old one and free this one.  */
  2946.   hashcode = TYPE_HASH (component_type);
  2947.   t = type_hash_canon (hashcode, t);
  2948.  
  2949.   if (TYPE_SIZE (t) == 0)
  2950.     layout_type (t);
  2951.  
  2952.   return t;
  2953. }
  2954.  
  2955. /* Return OP, stripped of any conversions to wider types as much as is safe.
  2956.    Converting the value back to OP's type makes a value equivalent to OP.
  2957.  
  2958.    If FOR_TYPE is nonzero, we return a value which, if converted to
  2959.    type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
  2960.  
  2961.    If FOR_TYPE is nonzero, unaligned bit-field references may be changed to the
  2962.    narrowest type that can hold the value, even if they don't exactly fit.
  2963.    Otherwise, bit-field references are changed to a narrower type
  2964.    only if they can be fetched directly from memory in that type.
  2965.  
  2966.    OP must have integer, real or enumeral type.  Pointers are not allowed!
  2967.  
  2968.    There are some cases where the obvious value we could return
  2969.    would regenerate to OP if converted to OP's type, 
  2970.    but would not extend like OP to wider types.
  2971.    If FOR_TYPE indicates such extension is contemplated, we eschew such values.
  2972.    For example, if OP is (unsigned short)(signed char)-1,
  2973.    we avoid returning (signed char)-1 if FOR_TYPE is int,
  2974.    even though extending that to an unsigned short would regenerate OP,
  2975.    since the result of extending (signed char)-1 to (int)
  2976.    is different from (int) OP.  */
  2977.  
  2978. tree
  2979. get_unwidened (op, for_type)
  2980.      register tree op;
  2981.      tree for_type;
  2982. {
  2983.   /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension.  */
  2984.   /* TYPE_PRECISION is safe in place of type_precision since
  2985.      pointer types are not allowed.  */
  2986.   register tree type = TREE_TYPE (op);
  2987.   register unsigned final_prec
  2988.     = TYPE_PRECISION (for_type != 0 ? for_type : type);
  2989.   register int uns
  2990.     = (for_type != 0 && for_type != type
  2991.        && final_prec > TYPE_PRECISION (type)
  2992.        && TREE_UNSIGNED (type));
  2993.   register tree win = op;
  2994.  
  2995.   while (TREE_CODE (op) == NOP_EXPR)
  2996.     {
  2997.       register int bitschange
  2998.     = TYPE_PRECISION (TREE_TYPE (op))
  2999.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  3000.  
  3001.       /* Truncations are many-one so cannot be removed.
  3002.      Unless we are later going to truncate down even farther.  */
  3003.       if (bitschange < 0
  3004.       && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
  3005.     break;
  3006.  
  3007.       /* See what's inside this conversion.  If we decide to strip it,
  3008.      we will set WIN.  */
  3009.       op = TREE_OPERAND (op, 0);
  3010.  
  3011.       /* If we have not stripped any zero-extensions (uns is 0),
  3012.      we can strip any kind of extension.
  3013.      If we have previously stripped a zero-extension,
  3014.      only zero-extensions can safely be stripped.
  3015.      Any extension can be stripped if the bits it would produce
  3016.      are all going to be discarded later by truncating to FOR_TYPE.  */
  3017.  
  3018.       if (bitschange > 0)
  3019.     {
  3020.       if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
  3021.         win = op;
  3022.       /* TREE_UNSIGNED says whether this is a zero-extension.
  3023.          Let's avoid computing it if it does not affect WIN
  3024.          and if UNS will not be needed again.  */
  3025.       if ((uns || TREE_CODE (op) == NOP_EXPR)
  3026.           && TREE_UNSIGNED (TREE_TYPE (op)))
  3027.         {
  3028.           uns = 1;
  3029.           win = op;
  3030.         }
  3031.     }
  3032.     }
  3033.  
  3034.   if (TREE_CODE (op) == COMPONENT_REF
  3035.       /* Since type_for_size always gives an integer type.  */
  3036.       && TREE_CODE (type) != REAL_TYPE)
  3037.     {
  3038.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  3039.       type = type_for_size (innerprec, TREE_UNSIGNED (TREE_OPERAND (op, 1)));
  3040.  
  3041.       /* We can get this structure field in the narrowest type it fits in.
  3042.      If FOR_TYPE is 0, do this only for a field that matches the
  3043.      narrower type exactly and is aligned for it
  3044.      The resulting extension to its nominal type (a fullword type)
  3045.      must fit the same conditions as for other extensions.  */
  3046.  
  3047.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  3048.       && (for_type || ! DECL_BIT_FIELD (TREE_OPERAND (op, 1)))
  3049.       && (! uns || final_prec <= innerprec
  3050.           || TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  3051.       && type != 0)
  3052.     {
  3053.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  3054.                TREE_OPERAND (op, 1));
  3055.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  3056.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  3057.       TREE_RAISES (win) = TREE_RAISES (op);
  3058.     }
  3059.     }
  3060.   return win;
  3061. }
  3062.  
  3063. /* Return OP or a simpler expression for a narrower value
  3064.    which can be sign-extended or zero-extended to give back OP.
  3065.    Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
  3066.    or 0 if the value should be sign-extended.  */
  3067.  
  3068. tree
  3069. get_narrower (op, unsignedp_ptr)
  3070.      register tree op;
  3071.      int *unsignedp_ptr;
  3072. {
  3073.   register int uns = 0;
  3074.   int first = 1;
  3075.   register tree win = op;
  3076.  
  3077.   while (TREE_CODE (op) == NOP_EXPR)
  3078.     {
  3079.       register int bitschange
  3080.     = TYPE_PRECISION (TREE_TYPE (op))
  3081.       - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
  3082.  
  3083.       /* Truncations are many-one so cannot be removed.  */
  3084.       if (bitschange < 0)
  3085.     break;
  3086.  
  3087.       /* See what's inside this conversion.  If we decide to strip it,
  3088.      we will set WIN.  */
  3089.       op = TREE_OPERAND (op, 0);
  3090.  
  3091.       if (bitschange > 0)
  3092.     {
  3093.       /* An extension: the outermost one can be stripped,
  3094.          but remember whether it is zero or sign extension.  */
  3095.       if (first)
  3096.         uns = TREE_UNSIGNED (TREE_TYPE (op));
  3097.       /* Otherwise, if a sign extension has been stripped,
  3098.          only sign extensions can now be stripped;
  3099.          if a zero extension has been stripped, only zero-extensions.  */
  3100.       else if (uns != TREE_UNSIGNED (TREE_TYPE (op)))
  3101.         break;
  3102.       first = 0;
  3103.     }
  3104.       /* A change in nominal type can always be stripped.  */
  3105.  
  3106.       win = op;
  3107.     }
  3108.  
  3109.   if (TREE_CODE (op) == COMPONENT_REF
  3110.       /* Since type_for_size always gives an integer type.  */
  3111.       && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE)
  3112.     {
  3113.       unsigned innerprec = TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (op, 1)));
  3114.       tree type = type_for_size (innerprec, TREE_UNSIGNED (op));
  3115.  
  3116.       /* We can get this structure field in a narrower type that fits it,
  3117.      but the resulting extension to its nominal type (a fullword type)
  3118.      must satisfy the same conditions as for other extensions.
  3119.  
  3120.      Do this only for fields that are aligned (not bit-fields),
  3121.      because when bit-field insns will be used there is no
  3122.      advantage in doing this.  */
  3123.  
  3124.       if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
  3125.       && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
  3126.       && (first || uns == TREE_UNSIGNED (TREE_OPERAND (op, 1)))
  3127.       && type != 0)
  3128.     {
  3129.       if (first)
  3130.         uns = TREE_UNSIGNED (TREE_OPERAND (op, 1));
  3131.       win = build (COMPONENT_REF, type, TREE_OPERAND (op, 0),
  3132.                TREE_OPERAND (op, 1));
  3133.       TREE_SIDE_EFFECTS (win) = TREE_SIDE_EFFECTS (op);
  3134.       TREE_THIS_VOLATILE (win) = TREE_THIS_VOLATILE (op);
  3135.       TREE_RAISES (win) = TREE_RAISES (op);
  3136.     }
  3137.     }
  3138.   *unsignedp_ptr = uns;
  3139.   return win;
  3140. }
  3141.  
  3142. /* Return the precision of a type, for arithmetic purposes.
  3143.    Supports all types on which arithmetic is possible
  3144.    (including pointer types).
  3145.    It's not clear yet what will be right for complex types.  */
  3146.  
  3147. int
  3148. type_precision (type)
  3149.      register tree type;
  3150. {
  3151.   return ((TREE_CODE (type) == INTEGER_TYPE
  3152.        || TREE_CODE (type) == ENUMERAL_TYPE
  3153.        || TREE_CODE (type) == REAL_TYPE)
  3154.       ? TYPE_PRECISION (type) : POINTER_SIZE);
  3155. }
  3156.  
  3157. /* Nonzero if integer constant C has a value that is permissible
  3158.    for type TYPE (an INTEGER_TYPE).  */
  3159.  
  3160. int
  3161. int_fits_type_p (c, type)
  3162.      tree c, type;
  3163. {
  3164.   if (TREE_UNSIGNED (type))
  3165.     return (!INT_CST_LT_UNSIGNED (TYPE_MAX_VALUE (type), c)
  3166.         && !INT_CST_LT_UNSIGNED (c, TYPE_MIN_VALUE (type))
  3167.         && (TREE_INT_CST_HIGH (c) >= 0 || TREE_UNSIGNED (TREE_TYPE (c))));
  3168.   else
  3169.     return (!INT_CST_LT (TYPE_MAX_VALUE (type), c)
  3170.         && !INT_CST_LT (c, TYPE_MIN_VALUE (type))
  3171.         && (TREE_INT_CST_HIGH (c) >= 0 || !TREE_UNSIGNED (TREE_TYPE (c))));
  3172. }
  3173.  
  3174. /* Return the innermost context enclosing DECL that is
  3175.    a FUNCTION_DECL, or zero if none.  */
  3176.  
  3177. tree
  3178. decl_function_context (decl)
  3179.      tree decl;
  3180. {
  3181.   tree context;
  3182.  
  3183.   if (TREE_CODE (decl) == ERROR_MARK)
  3184.     return 0;
  3185.  
  3186.   if (TREE_CODE (decl) == SAVE_EXPR)
  3187.     context = SAVE_EXPR_CONTEXT (decl);
  3188.   else
  3189.     context = DECL_CONTEXT (decl);
  3190.  
  3191.   while (context && TREE_CODE (context) != FUNCTION_DECL)
  3192.     {
  3193.       if (TREE_CODE (context) == RECORD_TYPE
  3194.       || TREE_CODE (context) == UNION_TYPE)
  3195.     context = TYPE_CONTEXT (context);
  3196.       else if (TREE_CODE (context) == TYPE_DECL)
  3197.     context = DECL_CONTEXT (context);
  3198.       else if (TREE_CODE (context) == BLOCK)
  3199.     context = BLOCK_SUPERCONTEXT (context);
  3200.       else
  3201.     /* Unhandled CONTEXT !?  */
  3202.     abort ();
  3203.     }
  3204.  
  3205.   return context;
  3206. }
  3207.  
  3208. /* Return the innermost context enclosing DECL that is
  3209.    a RECORD_TYPE or UNION_TYPE, or zero if none.
  3210.    TYPE_DECLs and FUNCTION_DECLs are transparent to this function.  */
  3211.  
  3212. tree
  3213. decl_type_context (decl)
  3214.      tree decl;
  3215. {
  3216.   tree context = DECL_CONTEXT (decl);
  3217.  
  3218.   while (context)
  3219.     {
  3220.       if (TREE_CODE (context) == RECORD_TYPE
  3221.       || TREE_CODE (context) == UNION_TYPE)
  3222.     return context;
  3223.       if (TREE_CODE (context) == TYPE_DECL
  3224.       || TREE_CODE (context) == FUNCTION_DECL)
  3225.     context = DECL_CONTEXT (context);
  3226.       else if (TREE_CODE (context) == BLOCK)
  3227.     context = BLOCK_SUPERCONTEXT (context);
  3228.       else
  3229.     /* Unhandled CONTEXT!?  */
  3230.     abort ();
  3231.     }
  3232.   return NULL_TREE;
  3233. }
  3234.  
  3235. void
  3236. print_obstack_statistics (str, o)
  3237.      char *str;
  3238.      struct obstack *o;
  3239. {
  3240.   struct _obstack_chunk *chunk = o->chunk;
  3241.   int n_chunks = 0;
  3242.   int n_alloc = 0;
  3243.  
  3244.   while (chunk)
  3245.     {
  3246.       n_chunks += 1;
  3247.       n_alloc += chunk->limit - &chunk->contents[0];
  3248.       chunk = chunk->prev;
  3249.     }
  3250.   fprintf (stderr, "obstack %s: %d bytes, %d chunks\n",
  3251.        str, n_alloc, n_chunks);
  3252. }
  3253. void
  3254. dump_tree_statistics ()
  3255. {
  3256.   int i;
  3257.   int total_nodes, total_bytes;
  3258.  
  3259.   fprintf (stderr, "\n??? tree nodes created\n\n");
  3260. #ifdef GATHER_STATISTICS
  3261.   fprintf (stderr, "Kind                  Nodes     Bytes\n");
  3262.   fprintf (stderr, "-------------------------------------\n");
  3263.   total_nodes = total_bytes = 0;
  3264.   for (i = 0; i < (int) all_kinds; i++)
  3265.     {
  3266.       fprintf (stderr, "%-20s %6d %9d\n", tree_node_kind_names[i],
  3267.            tree_node_counts[i], tree_node_sizes[i]);
  3268.       total_nodes += tree_node_counts[i];
  3269.       total_bytes += tree_node_sizes[i];
  3270.     }
  3271.   fprintf (stderr, "%-20s        %9d\n", "identifier names", id_string_size);
  3272.   fprintf (stderr, "-------------------------------------\n");
  3273.   fprintf (stderr, "%-20s %6d %9d\n", "Total", total_nodes, total_bytes);
  3274.   fprintf (stderr, "-------------------------------------\n");
  3275. #else
  3276.   fprintf (stderr, "(No per-node statistics)\n");
  3277. #endif
  3278.   print_lang_statistics ();
  3279. }
  3280.